For multi-process and multi-threaded understanding (to be supplemented)

1, the concept of

  First is that concept. When it comes to the concept of concurrency, we must first build awareness of the multi-tasking programming. Meaning multi-tasking programming is to take full advantage of multi-core computer resources, improve operational efficiency of the program. There are two implementations of concurrency and parallelism.

  Concurrency : handle multiple tasks simultaneously, the kernel constantly switching between tasks to achieve the effect seems to perform multiple tasks simultaneously, the actual time for each task occupies only a kernel.

  Parallel : a plurality of tasks use a multicore computer resources while performing, when a plurality of tasks among parallel relationship.

  Multi-process and multi-threaded: So there are two ways to achieve concurrent programming.

  Process : program running in the computer once.

  •   Program is an executable file, a static possession disk.
  •   Process is a dynamic process description, possession of a computer running resources, there is a certain life cycle.

  Thread : Process [1] is referred to as a lightweight thread
     [2] may be used threads multicore computer resources, multitasking programming mode
     [3] is a minimum unit thread dispensing system kernel
     [4] for the process thread will be appreciated that the quests

2, multi-process and multi-threaded selected under different usage scenarios

  Multi-process and multi-threaded biggest feature - "the process is the smallest unit of resource allocation, the thread is the smallest unit of program execution."

  Summarizes the advantages and disadvantages of processes and threads :

    Process advantages: programming, debugging simple, high reliability.
    Process Disadvantages: create, destroy, slow switching speed, memory, resource large footprint.
    Thread advantages: create, destroy, fast switching speed, memory, small footprint.
    Thread drawback: programming, debugging complex and less reliable.

  The difference between process threads contact:

  1. Both are multi-tasking programming mode, the computer can use multi-core resources
  2. Create Delete consume computer resources processes than threads
  3. Independent process space, data without disturbing each other, have a special communication method; thread communication using global variables
  4. A process can have multiple branches threads, both have containment relationship
  5. Multiple threads share the process resources in a shared resource operations often need to synchronize exclusive deal
  6. Process thread has its own unique attribute flags in the system, such as ID, code segments, commands and so on.

 

    

Guess you like

Origin www.cnblogs.com/jason--/p/11444356.html