Chapter 4 Multi-threaded

4.1 thread

  Each thread is a basic unit used cpu, which includes a thread ID, the program counter, a register set, and stack. It is shared code segment, data segment and other operating system resources with other threads in the same process.

          

 

 

   Multithreaded programming advantages: responsiveness, resource sharing, economic, and scalability.

4.2 Multicore Programming

  For single-core systems, concurrent with the time only mean that the thread alternately executed because the processing core can execute a single thread at the same time.

  For multi-core system, showing concurrent threads run in parallel, because the system can assign a separate core for each thread.

  Concurrency and parallelism of the difference between:

    Parallel systems can perform multiple tasks simultaneously, the system supports multiple concurrent tasks, all tasks are allowed to progress. No parallel, concurrent also possible.

More than 4.3 threading model

  To provide support thread by thread user and kernel threads. User thread is located above the kernel threads, its management do not need kernel support, and kernel threads to directly support the management by the operating system.

Many-to-model

  Maps multiple threads to a kernel thread.

  Thread management is done by the thread library user control, and therefore high efficiency. But a thread of execution blocking system calls, then the whole process will be blocked. At any one time only one thread can access the kernel, not a plurality of threads run in parallel on a multi-core processing system.

One model

  Maps each user thread to a kernel thread.

  When a thread is blocked execution system, allowing other threads to continue, while also allowing multiple threads running in parallel on a multi-core system. The only drawback is to create a user thread will create a kernel thread, because the kernel thread creation overhead will affect the performance of your application, so most of this model limits the number of threads supported by the system.

To-many model

  Multiplexing a plurality of user threads to the same number or fewer kernel threads.

  You can create as many user threads, and parallel execution on multi-core systems. When a thread executes blocking system call, the kernel can schedule another thread to perform.

4.4 Thread Library

  Thread library provides an API for creating and managing threads for programmers.

4.5 implicit multithreading

  When you create and manage multiple threads to the compiler and runtime libraries to complete, this strategy is called implicit thread.

4.5.1 Thread Pool

  Idea: to create a process that began when a certain number of threads, and added to the pool waiting for work, when the request is received, it will wake up in a pool of available threads, the thread once the task is completed, it will be returned to the pool waiting for work. If there are no threads available late, then waits until the empty thread.  

Guess you like

Origin www.cnblogs.com/astonc/p/12150815.html