Python base-----Processes and threads

Source: Internet
Author: User

First, the process

1. What is a process?

The 1.1 process is a dynamic execution of a program on a data set. The process is generally composed of three parts: program, data set and process control block.

1.2 A program is a process that needs to complete those functions and how to do it.

1.3 Datasets are resources that the program needs to use during execution.

1.4 The Process Control block is used to record the external characteristics of the process, describe the process of execution change process, the system can use him to control and manage the process, he is the system-aware process exists only

A logo

Second, the thread

1. Why is it wired?

1.1 Thread is to reduce the consumption of the context switch, improve the concurrency of the system, break through a process can only do one thing limitations.

2. What is a thread?

The 2.1 thread is a lightweight process, which is a basic CPU execution unit and the smallest unit in the process of program execution. By thread ID, program counter, register collection,

and stacks together.

· 3. What are the benefits of threading?

3.1 Reduce the consumption of concurrent execution of the program, improve the concurrency performance of the operating system, but the thread does not have its own system resources, is allocated by the process.

Iii. relationship of processes and threads

1. A thread can belong to only one process, while a process may have multiple threads, but there must be at least one main thread.

2. System resources are allocated to the process, and all the threads under the process share all the resources assigned to the process.

3. The CPU is assigned to the thread, that is, the thread is actually running on the CPU.

Iv. Parallelism and concurrency

1. What is parallel processing?

Parallel processing refers to a computer CPU colleague working on two or more than two threads, or a program.

2, what is concurrent processing?

Concurrent processing refers to how many processes a computer's CPU switches to handle over a period of time.

3, the relationship between the two?

Parallelism is a subset of concurrency, and concurrency is the parent set of parallelism.

4, Supplementary knowledge points

Serial: Serial means that the CPU executes the program sequentially.

V, synchronous and asynchronous

1. What is synchronization?

Synchronization is when a process executes a request, and if the request takes a while to return information, the process waits until

The return information for the request is received before the following operation is performed.

2. What is async?

Asynchronous refers to a process that executes a request, if it takes a while for the request to return information, but the process does not wait for the request, but instead directly performs the following action

When the request has return information, the operating system notifies the process, and this mechanism of asynchronous processing greatly improves the execution efficiency of the program.

Six, intensive tasks

1. IO-intensive tasks

The program has a lot of IO operations, such as Sleep,input,accert, and so on.

2. Compute-intensive tasks

The program has a lot of computation operations, except the IO operation is the computation operation.

3. In the case of multi-threaded handlers, IO-intensive tasks are more advantageous than computationally intensive tasks.

4, Supplement: For Python, can not take advantage of multicore, because his process has a lock lock mechanism,

    

  

    

      

      

Python base-----Processes and threads

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.