Linux Thread recognize learning _ thread

First, understanding the thread

  1, thread: Linux Thread is a lightweight process to achieve the simulation process pcb, pcb controlling a running description, and with these pcb

        Share the same virtual address space, shared process in most of the resources, so more lightweight compared to conventional processes;

  2, exclusive and sharing thread

  Operating system process is the basic unit of resource allocation: resource allocation system up and running after the program is to give the whole process group;

  A thread is the basic unit of CPU scheduling: scheduling program implemented by the CPU scheduling pcb;

    Unique: In order to avoid confusion between calls to thread stack, each thread has its own stack area, register, thread id, scheduling priority, errno, signal shielding the word;

    Shared: virtual address space (code segment - segment data), the file descriptor table, signal processing, user id and group id, the current working directory / directory

  3, thread exception

    1> If there is a single thread other than zero, wild pointer problems led to the collapse of the thread, along with the process can lead to collapse;

    2> A thread is executing a branch processes, threads appear abnormal, the process will be abnormal;

  4, uses thread

    1> rational use can improve the efficiency of the CPU-intensive procedures;

    2> rational use may improve I / O-intensive procedures user experience;

  5, the advantages of thread

    1> to create a thread is much less than the cost of creating a process;

    Compared switch 2> and processes the workload required to switch between the operating system threads rarely;

    3> Thread consumes fewer resources than the process;

    4> may be the number of parallel processors to take advantage of multiple;

    5> compute-intensive applications, to run on the multiprocessor system, the calculated decomposed into multiple threads is implemented;

    6> I / O intensive applications, in order to improve performance, the I / O operations overlap. Threads can while waiting for a different IO operations;

  6, shortcomings thread

    1> performance loss: If a large number of threads, it's created, switching, destruction will increase the additional synchronization and scheduling overhead,

          And available resources are the same, so there will be a large performance loss;

    2> robustness low: lack of protection between threads and threads;

    3> lack of access control: The process is the basic granularity of access control, calling some OS functions will affect the whole process in a thread;

Guess you like

Origin www.cnblogs.com/bj3251101/p/11466436.html