Threads, processes, coroutines basic understanding

Process: Examples of a computer program executed by the program data segments PCB composition, is the basic unit of resource allocation and scheduling computer, but also the container threads.

Thread: Thread, also known as lightweight processes, is the smallest unit of program execution itself has only a small part of the implementation of the necessary resources.

Coroutine: · coroutines, also known as micro-threading, the user can control the timing of their own coroutine switch, no longer need to fall into kernel mode system. Threads and processes are faced with the problem of switching kernel mode and user mode, consuming a lot of switching time.

 

the difference:

1) threads share memory space, independent memory process

Between 2) direct communication between threads, interprocess communication must pass through an intermediate proxy

3) can control each other between threads of the same process, but the process can only control the child process

4) thread creation is very simple, but to create a new process must be a clone of the parent process

5) changing the main Chen will affect other threads, but the change will not affect the parent process child process

 

GIL: Global Interpreter Lock, at the same time point system, only one thread is interpreted interpreter, can not be done in parallel, can not take full advantage of multi-core resources.

python is similar to so-called multi-threaded multi-process programming under a single-core CPU situation.

How to solve the problem GIL lock:

1) Replace the cpython to jpython

2) the use of multi-process multi-threaded task execution

3) to achieve multi-threaded through C

Mutex: multi-threaded, to ensure an orderly modified data is modified, does not produce data modification confusion.

 

Guess you like

Origin www.cnblogs.com/zhanghaibin16/p/11781337.html