Thread Past and Present

process

Early computer has only a single-core CPU, operating system, CPU scheduling the process as a unit. The process has a separate memory address space, was not yet the concept of threads.
Process has three states, namely, blocking, ready to run. When the resources are not in place the required process is blocked , when the process but not have the resources CPU scheduling is ready , when the process has the resources used by the CPU and is scheduled to run state .

User mode thread

As procedures become more complex, context switching also more expensive to produce scheduling, so the programmer can not puzzling at the same address space (Address Space), executing a plurality of processes. But the operating system kernel protection purposes, prohibit direct access to the address space of a process to another process.
Since the operating system does not support the programmer decided to maintain in user space threads a table, it can achieve on their own schedule of "process", which is the user mode thread , now generally called the shred or coroutines .
User mode thread advantages are:

  1. Thread switching speed in user space much faster than achieved in the operating system kernel
  2. Programmers can implement their own garbage collector to reclaim thread
  3. When too many threads, due in user space thread table maintenance, operating system will not take up a lot of space

There are disadvantages user mode thread:

  1. Since the operating system is not aware of the existence of threads, so that when one thread in a process system calls, such as page faults caused by thread is blocked, then the operating system will block the entire process, even if the process was still working in other threads
  2. If the process does not release the CPU a thread for a long time, because the user space and no clock interrupt mechanism, this process will lead to other threads get the CPU keeps waiting

Kernel mode threads

Accompanied by the emergence of multi-core CPU, operating system have begun to support the thread. Kernel space maintains a table of threads, thread scheduling by the kernel, which is the kernel mode thread , also known as lightweight process (Light Weight Process, LWP). He said today that thread, if not specified, all kernel threads .
Kernel mode thread advantages are:

  1. When a thread is blocked, you can choose the operating system of the CPU to other threads in the same process, or other threads in the process, and for the user mode thread scheduling can only be performed in this process until the operating system stripped of the current CPU process
    weaknesses kernel mode threads are:
  2. All that may block the calling thread is System Call, compared causing thread blocking in user space System runtime call, much higher costs
  3. Creating and higher costs destruction. To reduce costs, when a thread need to be destroyed, only the destroyed marking; when a new thread is required, it can be multiplexed threads labeled destroyed
  4. Signal receiving system unit is process, not thread, a thread which receives the signal system in the process it

Core Logic

"Single-core CPU can only be run at the same time a process" in the past for a long period of time is right, until simultaneous multithreading (SMT) appears. A superscalar processor (a CPU physical core) can be run simultaneously more than one thread, such as Intel's hyperthreading a physical support core running two threads. Speak a few core CPU cores generally refers to the physical core number , if the number of cores generally refers to a logical direct say the number of threads, it also supports several core-logic sets of architectural state and a few threads.

"Single-process multi-threaded dual-core CPU can be used while the" no problem in the mainstream operating system. The operating system kernel, the CPU resources are directly visible logic core , can schedule tasks directly into the CPU to achieve general support thread, single-core CPU can run multiple tasks simultaneously.
The concept of different operating systems in different tasks:

  • Windows scheduling is the thread, but the thread of the process vessel
  • Linux kernel does not distinguish between processes or threads, scheduling tasks can be implemented as a process or thread in the process in user space.

reference

Guess you like

Origin www.cnblogs.com/mougg/p/12319733.html