1. Mutual Exclusion and Synchronization
1. Mutual Exclusion: 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.
2. 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.
3. synchronization is a more complex type of mutex, while mutex is a special type of synchronization.
2. Communication and Synchronization
Inter-process synchronization is also a kind of inter-process communication (because of information exchange). Of course, it is also a kind of original inter-process communication, but it is also the cornerstone of a more advanced inter-process communication mechanism.
The same applies to threads.
Iii. Differences between the critical section and mutex
1. The critical section can only be used for mutually exclusive access between objects in the same process. The mutex can be used for mutually exclusive access between object processes or threads.
2. The critical section is a non-kernel object. The lock operation is performed only in the user State, and the speed is fast. The mutex is the kernel object. The lock operation is performed in the core state, which is slow.
3. The critical section and mutex are available on the Windows platform. in Linux, only mutex is available.
Iv. Linux IPC
1. Classic IPC:
(1) pipelines, named pipelines // the most basic and common
(2) Message Queue, semaphores, and shared storage
// Divided into posix ipc and System v ipc. shared storage is the fastest way to communicate between processes running on the same machine
2 advanced IPC: Stream pipeline and life-honored Pipeline
(The above is the IPC between processes on the same host)
3. support IPC for processes on different hosts: Set interfaces and streams
5. Inter-thread communication mechanism:
1. mutex lock
2. Condition Variables
3. read/write lock
4. Signal lights