[Operating system] thread

Disclaimer: This article is a blogger original article. Shall not be reproduced without the consent of bloggers. https://blog.csdn.net/RowandJJ/article/details/27962769
Preface:
Process concept includes two different characteristics: 1 Resource All rights; 2 scheduling / running ability..
Since these two characteristics are independent, then the operating system should be able to handle them independently, which leads to the concept of threads.

To distinguish between these two characteristics, we dispatched a unit called threads or lightweight processes, but the unit has all the right resources is often still referred to the process.


The concept of threads:
The ability to run multiple concurrent paths refers to the operating system supports a single process.

Thread strengths:
1. Create a thread created directly in the process than the process faster.
2. terminate the thread faster than the termination of the process;
3. Switch within the same process than the process of switching threads quickly.
4. Thread improve the communication efficiency of different operating programs.

(Involved in the communication process needs kernel. The shared memory and files between multiple threads within a process without calling the kernel)


Note : The process pending operations involving the address space of a process of swapping out memory address space to make room for other processes, since all the threads in a process share the same address space, so they are the same when they were suspended.


Thread Category:
1. User-level threads:
    In a pure user-level thread software, all work-related thread management by the application is completed. There is less awareness of kernel threads. No matter what the application can use the thread library is designed to be multi-threaded procedures.

Thread library is used for a user-level thread management course package, which includes creating and destroying threads for code, code that passes messages and data between threads, thread scheduling code to run, as well as saving and restoring thread contexts code.

    Advantages:
    1. The thread switch need not privileged kernel state;
    2. The scheduling can be associated with the application;
    3. user-level threads to run regardless of what operating system does not require changes to the underlying kernel to support user-level threads
    Disadvantages:
    1. user-level threads running system calls, not only this thread is blocked, the process all threads are blocked.
    2. kernel only once to assign a process to a processor, so once the process has only one thread can run.
2. kernel-level threads:
    Pure kernel-level threads. All work on the thread management is completed by the kernel, no part of the application thread management code. The disadvantage is that there is a thread delivered to a thread. The kernel needs a state transition.



























Guess you like

Origin www.cnblogs.com/ldxsuanfa/p/10961951.html