The tube, coroutine

  • The tube: the introduction of semaphore mechanism to solve the problems described synchronization process, but a large number of semaphore synchronization is not easy to manage dispersed in each process, the system may also lead to a deadlock. Therefore, all processes synchronous operation of a certain kind of critical resources are pooled, here abbreviated as A (synchronous operation of all processes on other critical resources are together referred to as B). Equivalent to the tube wall, it is the shared variables and a number of its operations process (A, B, etc.) surrounded them, when all the processes to access critical resources, must enter through the tube in order, and each tube pass times only allows a process to enter the tube, in order to achieve a mutually exclusive processes.
  • Coroutine: coroutine lightweight thread is a user-state, coroutine scheduling entirely controlled by the user. Coroutine has its own stack and register context. When coroutine scheduled handover, the context save registers to the stack and elsewhere, when cut back, context restore a previously saved registers and stack. Direct overhead substantially no stack operation is switched core can not access the locked global variables, very fast context switching.

to sum up:

  1. A thread can have a plurality of co-routines, the process may have a plurality of individual coroutine, so it can be used in python multicore CPU.
  2. Thread processes are synchronization mechanisms, and coroutine is asynchronous.

Guess you like

Origin blog.csdn.net/weixin_41539756/article/details/95305926