Python3 Process 4
Inter-Process synchronization Mutex method:
From multiprocessing import Lock
Create a process Lock object
Lock = Lock ()
Lock.acquire () Lock the critical section
Lock.release () unlocks the critical section
Description: 1, the concrete implementation of acquire () is a conditional blocking function;
2, when any one of the processes first acquire operation, the other process attempts to acquire operation will block, until the lock object is release other process CIA can do next
Acquire operation;
With Lock: Also can be implemented lock, unlocked
Thread:
1, the thread can also use the multi-core resources of the computer, is also one of the multi-task programming method;
2, the thread is also called the lightweight process, in the concurrency and the same process, but the destruction of resources at the time of creation;
Description: 1, a process can contain multiple threads, this multiple threads share the resources of the process;
2, multiple threads because of the sharing process resources, so in the communication often adopt the way of global variables;
3, the thread also has its own unique resources, such as TTD instruction set;
Multi-process and multi-threaded differences and linkages:
1, multi-process and multithreading are multi-task programming, can use computer multicore;
2, the process is created to consume more resources than the thread;
3, the process of space independent data is more secure, there is a specialized process of communication between the interaction;
4, a process contains multiple threads, so threads share process resources and do not have a dedicated means of communication, relying on global variables for communication. Often need to use synchronous mutual exclusion mechanism, logic need to consider more;
5, process threads have their own unique resources, multiple related tasks when using multi-threaded resource consumption less, if it is not related to a number of unrelated tasks are not applicable to all use threads;
Python Road Pythonthread, fourth, process 4