The role of process and thread lock lock?

Thread lock:

 Multiple threads can run multiple tasks but when multiple threads access shared data may result in data is not synchronized , even wrong! so, do not use thread lock, can lead to errors

 

Everyone is familiar with, is mainly used to process the code block lock. When a block of code or method of use of the lock , then at the same time there is at most only a thread for executing the section code.

When there are multiple threads access the same object locking method / code block, only one thread at the same time the implementation of the remaining thread must wait for the current thread to execute the code segment after the execution. However, the rest of the threads can access the non-locking block of the object.

Process lock:

But also to control the same operating system in multiple processes to access a shared resource,

Just because the independence of the program, each process can not be controlled by other processes access to resources,

But the amount of signal can use a local control system (operating system basics).

 

Advantages: ensure resource synchronization 
Cons: There will definitely slow wait

Guess you like

Origin www.cnblogs.com/Rivend/p/12058156.html
Recommended