thread

1、 Thread concept

A process is an executing program. In the operating system, the process is the smallest unit for system resource allocation, scheduling and management. The process has an independent memory unit during execution. For example, windows uses processes as the minimum isolation unit. Each process has its own data segment and program segment, and has nothing to do with other processes.

One or more threads constitute a process (the operating system takes the process as the unit, while the process takes the thread as the unit, and there must be a main thread in the process).

In order to solve the waste of process scheduling resources and share resources, threads appear. Thread is the basic unit of CPU scheduling and dispatching. It can share all the resources owned by the process with other threads belonging to the same process, and multiple threads share memory, which greatly improves the running efficiency of the program.

If a process is gone, the thread will certainly disappear. If the thread disappears, but the process may not disappear. And all threads are based on the process and run at the same time.

2、 Two ways to create threads and their differences

1 inherit thread class

1.1 example code

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>