In-depth understanding of computer systems Chapter XII second time concurrent programming part1

 

Three ways to construct a concurrent program and its advantages and disadvantages

1, process

In this way, each logical process is a control flow to and maintained by the kernel scheduler. Because the process has independent virtual address space, you want to communicate with other flow control flow must be some kind of explicit inter-process communication mechanism.

advantage:

Since the process has a separate address space, so a process can not accidentally overwrite another process's virtual memory, which eliminates many confusing error

Disadvantages:

(1) or due process has a separate address space, so that the process becomes more difficult to share state information. In order to share information, they must use explicit IPC (interprocess communication) mechanism.

(2) Due to the high process control and IPC overhead, so this approach is relatively slow

2, I / O multiplexer

In this form of concurrent programming, the application in the context of a process of explicitly schedule their own logic flow. The logic flow is modeled as a state machine, the file descriptor after the data arrives, the main program explicitly convert from one state to another. Because the program is a separate process, so all the streams share the same address space.

advantage:

Than process-based design (1) gives the programmer more control over the program behavior.

(2) based on I / O multiplexing event driven server is running in the context of a single process, so that each can access the logical flow of the entire address space. This makes the shared data between the flow becomes easy.

(3) and runs as a single process-related advantage is that you can use the familiar debugging tools, such as GDB, to debug your concurrent server, just as the order of the program.

(4) event-driven design is often much more efficient than a process-based design, because they do not require the scheduling process context switch to a new stream

Disadvantages:

(1) the coding complexity

(2) can not take full advantage of multi-core processors

3, thread

A thread is a single operating logic flow of the process context, scheduled by the kernel. You can think of a thread as a hybrid of two other ways, like the process stream as scheduled by the kernel, and like I / O multiplexing as to share the same virtual address space.

advantage:

(1) to take advantage of multi-core servers

(2) fast

Room (3) threads share data very convenient

Disadvantages:

Since the same process, it is easy to produce thread-safety issues

 

Interprocess communication

1, a communication pipe anonymous

2, Advanced pipe communication

3, named pipe communications

4, the communication message queue

5, the signal amount of traffic

6, the signal

7, the shared memory communication

8, the communication socket

reference:

https://blog.csdn.net/violet_echo_0908/article/details/51201278

Guess you like

Origin www.cnblogs.com/stone94/p/12079362.html