Synchronizing processes

Multiple processes can work together to perform a given task. Usually, they share data. It is important that access to shared data by various processes does not produce inconsistent data. Processes that cooperate by sharing data must, therefore, act in an orderly manner in order for that data to be accessible. Synchronization primitives are quite like those encountered for the library and threading.

Synchronization primitives are as follows:

  • Lock: This object can be in either the locked or unlocked state. A locked object has two methods, acquire() and release(), to manage access to a shared resource.
  • Event: This object realizes simple communication between processes; one process signals an event and the other processes wait for it. An event object has two methods, set() and clear(), to manage its own internal flag.
  • Condition: This object is used to synchronize parts of a workflow, in sequential or parallel processes. It has two basic methods: wait() is used to wait for a condition and notify_all() is used to communicate the condition that was applied.
  • Semaphore: This is used to share a common resource, for example, to support a fixed number of simultaneous connections.
  • RLock: This defines the recursive lock object. The methods and functionality of RLock are the same as the threading module.
  • Barrier: This divides a program into phases as it requires all processes to reach the barrier before any of the proceeds. Code that is executed after a barrier cannot be concurrent with the code that was executed before the barrier.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.102.225