Synchronous and asynchronous review new content lock, signal, time mechanism

Course Review:

  Parallel: two processes occur at the same point in time

  Concurrency: two processes running at the same time interval

  Sync: perform a certain task must rely on the return value of another task

  Asynchronous: perform a certain task, it does not rely on the return of another task, just need to tell another job soon

  Obstruction: Because the program is similar to IO wait, wait for the event can not proceed as a result of

  Non-blocking: The program encountered similar IO operations, not block waiting for, if not promptly treated IO, it error or skip other operations

Process methods and properties:

  Method: start () to open a child process

      join become synchronous asynchronous, so that the parent process to wait for the end of the implementation of the child, and then proceed

      is_alive determine whether the process is still alive

      terminate kill the process

  Attributes:

      The name of the child's name

      pid pid of the child process

      daemon process set to daemon, to a True representatives daemon, the default is False

Daemon:

    Features:

      With the code of the parent process is finished until the end

      Daemon can not create a child process

      Daemon must be set before the start

Communication between the inter process Communication Process - IPC

Today contents:  

  Learning lock mechanism

    l=Lock()

    A lock with a key

     The keys, open the door l.acquire ()

     Also key, lock l.release ()

  Learning signaling mechanism

    SEM = semaphore (n)

    n: it refers to initialize a lock with a few keys, an int

    The keys, lock the door l.acquire ()

    In other keys, open the door l.release ()

    Signal mechanism more than a locking mechanism counter, this counter is used to record the current remaining few keys

    When the counter is 0, indicating there is no key, this time acquire () in the blocked

    For counter, the time did not acquire, the internal counter is decremented by 1, Release () again, the counter is increased by one

 

  Learning event mechanism

    e = Event ()

    e.set () # will is_set () is set to True

    e.clear () # will is_set to False  

    () # Is_set determination value e.wait, if bool is True, non-blocking, bool value is False, then blocked

    e.is_set # logo

    Events by is_set () is bool value, de-identified e.wait () blocking state

    When is_set () bool value is False, e.wait () are blocked state

    When is_set () bool value is True, e.wait () unblocked

    When using the set (), it is to become is_set of bool True

    When using the clear (), right is_set of bool becomes False

 

 

 

Guess you like

Origin www.cnblogs.com/jerry-hou/p/11973245.html