How to synchronize processes
Multiple processes can work together to perform a given task. Usually, they share data. It is important that the 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 to access that data. Synchronization primitives are quite similar to those encountered for the library and threading.
They are as follows:
Lock: This object can be in one of the states: locked and unlocked. A lock object has two methods,
acquire()
andrelease()
, to manage the access to a shared resource.Event: This realizes simple communication between processes, one process signals an event and the other processes wait for it. An
Event
object has two methods,set()
andclear()
, 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 andnotify_all...