Linux Network Programming Reading Notes (10)

xiaoxiao2021-03-06  43

Chapter 15 Multirled Programming

· 15.1 concept

Threading such an entity, which is included in the process entity, has its own running line, can complete a certain task. It is shared all shared data and some environments in other processes in the process, and can compare certain tasks with other threads. Threads are often a lightweight process.

Multiple threads share the environments of the same process virtual space include code segments and most of the data, so a large number of replication creations that FORK needs to create are not required, and different threads can be transmitted through shared variables, and there is no need for complex IPC mechanisms.

The thread of the same process will run concurrently. Threads have independent: thread ID, register group value, thread stack, error return code variable errno, thread signal shield code, thread priority.

· 15.2 Classification of threads

1 user thread:

The implementation of the user thread is achieved by running time system code. The function of this part of the code is to save the register group information and other information you need to save when the thread is restored, and then put this structure in the thread scheduler, then select a priority thread in the thread queue. Then the information saved in the structure is replied to the running this thread.

2 kernel thread:

The kernel thread switch is implemented by the kernel scheduler, and the core scheduler entity is the same as the normal process.

· 15.3 Comparison of user threads and kernel threads

1 Distribution of CPU Time

The user thread is implemented by connecting the user-level thread bag in the process, so multiple threads of this process will allocate the CPU to this process. User-level threads cannot run at the same time in multiple CPU environments

The kernel threads and other processes compete together in the core scheduler, which can operate more good concurrency in the multi-CPU environment.

2 thread concurrency

Other threads will not be able to get the CPU time unless a running user-level thread is discarded by the CPU time to run the thread switching code. So some slow system calls will cause thread blockage, while other threads cannot be switched. Therefore, in the user-level thread, the system call that may be blocked will be replaced by no blocks. Also these reasons and CPU time allocation, greatly limiting the concurrency of user-level threads

The kernel thread is assigned to other processes or core threads by the core scheduler to other processes or core threads when blocking occurs.

3 thread scheduling overhead

The scheduling of user-level threads is small in all overheads; the kernel thread schedule is similar, so the overhead is large. Good concurrency of the kernel thread is exchanged with large overhead, and the user-level thread is more appropriate when the concurrent requirements are not very high.

· Use of thread function library

slightly

· Thread synchronization

Using unnamed signal, mutex, condition variables, signal variables, signal processors, and the like.

· Thread application

It is recommended to read other monographs in depth. Slightly ~

· 15.2 Classification of threads

1 user thread:

The implementation of the user thread is achieved by running time system code. The function of this part of the code is to save the register group information and other information you need to save when the thread is restored, and then put this structure in the thread scheduler, then select a priority thread in the thread queue. Then the information saved in the structure is replied to the running this thread.

2 kernel thread:

The kernel thread switch is implemented by the kernel scheduler, and the core scheduler entity is the same as the normal process.

· 15.3 Comparison of user threads and kernel threads

1 Distribution of CPU Time

The user thread is implemented by connecting the user-level thread bag in the process, so multiple threads of this process will allocate the CPU to this process. User-level threads cannot run at the same time in multiple CPU environments

The kernel threads and other processes compete together in the core scheduler, which can operate more good concurrency in the multi-CPU environment.

2 thread concurrency

Other threads will not be able to get the CPU time unless a running user-level thread is discarded by the CPU time to run the thread switching code. So some slow system calls will cause thread blockage, while other threads cannot be switched. Therefore, in the user-level thread, the system call that may be blocked will be replaced by no blocks. Also these reasons and CPU time allocation, greatly limiting the concurrency of user-level threads

The kernel thread is assigned to other processes or core threads by the core scheduler to other processes or core threads when blocking occurs. 3 thread scheduling overhead

The scheduling of user-level threads is small in all overheads; the kernel thread schedule is similar, so the overhead is large. Good concurrency of the kernel thread is exchanged with large overhead, and the user-level thread is more appropriate when the concurrent requirements are not very high.

· Use of thread function library

slightly

· Thread synchronization

Using unnamed signal, mutex, condition variables, signal variables, signal processors, and the like.

· Thread application

It is recommended to read other monographs in depth. Slightly ~

转载请注明原文地址:https://www.9cbs.com/read-57282.html

New Post(0)