Python Road Pythonthread, fourth, process 4

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.