Article Title: differences between thread synchronization and mutex in linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
There are two main relationships between the intersection processes: synchronization and mutual exclusion. Mutual exclusion refers to several program fragments that walk between different processes. When a process runs one of the program fragments, other processes cannot run any of them, the process can only run after the program fragment is run. The so-called synchronization refers to several program fragments that walk between different processes. They must run in strict accordance with a specified sequence, this order depends on the specific tasks to be completed.
Obviously, synchronization is a more complex type of mutex, while mutex is a special type of synchronization.
That is to say, mutual exclusion is that two threads cannot run at the same time. They will reject each other and must wait for one thread to run and the other to run. Synchronization cannot run at the same time, but he must run the corresponding thread in a certain order (also a mutex )!
Summary: mutex: A Resource allows only one visitor to access it at the same time, which is unique and exclusive. However, mutual exclusion cannot limit the access sequence of visitors to resources, that is, access is out of order.
Synchronization: on the basis of mutual exclusion (in most cases), visitors can access resources in an orderly manner through other mechanisms. In most cases, synchronization has implemented mutex, especially when all resources are written. In rare cases, multiple visitors are allowed to access resources at the same time.