[Concurrent programming] The communication method between processes, the communication method between threads process

When I was taking notes, I forgot where I saw it. I will study when I have time.

text

Pipe (pipe): Pipe is a half-duplex communication method. Data can only flow in one direction, and it can only be used between processes that are related. The kinship of the process usually refers to the parent-child process relationship.
Named pipe (namedpipe): The named pipe is also a half-duplex communication method, but it allows communication between unrelated processes.
Semaphore (semophore): A semaphore is a counter that can be used to control access to shared resources by multiple processes. It is often used as a locking mechanism to prevent other processes from accessing shared resources when a process is accessing the resource. Therefore, it is mainly used as a means of synchronization between processes and between different threads in the same process.
Message queue (messagequeue): The message queue is a linked list of messages, stored in the kernel and identified by the message queue identifier. The message queue overcomes the shortcomings of less signal transmission information, the pipeline can only carry unformatted byte streams, and the limited buffer size.
Signal (sinal): Signal is a more complex communication method used to notify the receiving process that an event has occurred.
Shared memory (shared memory): Shared memory is to map a section of memory that can be accessed by other processes. This shared memory is created by one process, but multiple processes can access it. Shared memory is the fastest IPC method, it is specially designed for the low efficiency of other inter-process communication methods. It is often used in conjunction with other communication mechanisms, such as signal two, to achieve synchronization and communication between processes.
Socket (socket): Socket is also an inter-process communication mechanism. Different from other communication mechanisms, it can be used for communication between different processes.

Thread

Locking mechanism: including mutual exclusion locks, condition variables, and read-write locks.
Mutex locks provide an exclusive method to prevent concurrent modification of data structures.
The read-write lock allows multiple threads to read shared data at the same time, and write operations are mutually exclusive.
Condition variables can block the process atomically until a certain condition is true. The conditions are tested under the protection of the mutex lock. Condition variables are always used with mutex locks. while+if+volatile variable
Semaphore: Including unnamed thread semaphore and named thread semaphore
Signal mechanism (Signal): similar to signal processing between processes

Java thread

synchoronized
wait/notify
lock condition
semaphore
countdownlatch
cyclicbarrier

The purpose of communication between threads is mainly for thread synchronization, so threads do not have a communication mechanism for data exchange as in process communication.

Guess you like

Origin blog.csdn.net/qq_41489540/article/details/109097284