This picturesque, yard sprinkler

Mutex:

Data is not shared between processes, but share the same set of file systems, so access to the same file, or print with a terminal is not a problem, and the results brought about by sharing brings competition, competition is confusion, so we the locks.

When the lock allows multiple processes modifying the same piece of data, at the same time only one task can be modified, that is, the serial changes at the expense of speed to ensure the security of data

Interprocess communication:

We know that the data between processes are isolated from each other, in order to achieve inter-process communication, it must only be by means of a number of technical, such as wooden stairs processing module, columns and pipelines, both of which are achievable v inter-process data transfer, because the queue is the pipeline false lock manner, so we can value the study cohort.

Create a shared process queue, queue is a multi-process safe queue, you can use the queue to pass data between multiple processes.

Producers and consumers:

Producers use patterns in concurrent programming can solve most of the concurrency problems. Data processing program to improve the overall ability to work through the balance of the production line and thread consumption in this mode speed

What is a producer-consumer model

Is strongly coupled to solve the producers and consumers through a container does not communicate directly with each other between producer and consumer, and communicate through the blocking queue

Why producers and consumers mode

In the world of the thread, the thread is the producer of production data, the consumer is the thread consumption data, in a multithreaded development, processing speed quickly if the producer, consumer Seoul processing speed is very slow, producers have and other consumers, in order to solve this problem, the introduction of producer and consumer patterns

Thread:

What is the thread

In traditional Caozuojitong, each process has an address space, but by default there is a thread of control

Like an assembly line process thread work, a pipeline must belong to a workshop, a workshop is a process engineering work

Therefore, the process of knowledge for it to focus its resources together, and on the implementation of the unit thread is cpu

The cost of creating a small thread

Create a process overhead is much larger than the thread, because different processes are competing

The common thread is the relationship of collaboration, will not do their own

The difference between threads and processes

1. Thread the process that created it shared address space, the process has its own address space

2. The thread can directly access its process's data segment, the process has its own copy of the data segment of the parent process

3. Thread the other threads can communicate directly with the inside of the process, but the process must use interprocess communication to communicate with sibling processes

4. Create a new thread is easy, but the new process needs to copy its parent process can

5. Thread the thread can be controlled at the same level in the same process, but the process can only control your own child process

6. The main thread sends changes may affect the behavior of other threads, but the parent process sends changes will not affect the team sent the child process

Why do you use multithreading

Multithreading refers to open multiple threads in a process / task is simply to make the public more than one address space, it must open multiple threads within a process.

GIL lock

gil is essentially a mutex, since it is a mutex, then he will be able to run concurrently become a serial, in order to control the sharing of data within the same time can only be modified by a task, thereby ensuring data security

For the calculation, the cpu better, but for the I / O is, no amount of cpu are useless, of course dui run a program, the cup with the increase, the efficiency will certainly improve

Because the program will not be pure number of basic computing or pure I / O, so we can only see a relative of a program in the end it is computationally intensive or i / o intensive to analyze the usefulness of multi-threaded python

Guess you like

Origin www.cnblogs.com/jimGraymane/p/11722423.html