We use lock to keep our valuables safe from thieves or mischief. Lock to door is for the valuables in house. Lock to bank locker is to keep gold or documents safe. Lock/password to an account is to keep is private. In the same manner, multiple processes requires lock to keep shared memory addresses private for particular operations. Lock will ensure that only one process will perform operation on it and others may not even access its value. Consider a bank software with two process. One is withdrawal and another is deposition. If both the processes run parallel with balance as shared memory address then, the value will of balance at the end of both processes will be wrong. To do this lock is applied to shared memory during each process. import multiprocessing ... lock = multiprocessing.Lock( ) ... lock.acquire( ) ... lock.release( ) ... Acquire is the function to lock the shared memory for one particular process for that moment. Release function will release the lock and this memory address is free to be accessed by another process.
Github Link
0 Comments
Leave a Reply. |
AuthorVinit is a computer scientist and roboticist. His research focuses on making machines intelligent. Categories |