Summary of Unix/Linux IPC and inter-thread Communication

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.