Conceptual Analysis of process and Thread in Qt
This article mainly introduces the conceptual analysis of processes and threads in Qt. It has certain reference value. Interested friends can refer to it. I hope you will have a lot of gains after reading this article. Let Xiaobian take you to understand it together.
I. Concept of process and thread
A. Concept of process
a. Programs are data files in computer storage systems
Source Code Program-Text file describing program behavior and functionality
Executable program-binary file, directly loaded and executed
The concept of process has two layers of concept, in the broad sense refers to a program on a data set of running activities, and in the chivalry refers to the program is loaded into memory after execution to get the process
The difference between a program and a process is that a program is a static file on the hard disk, while a process is a dynamic running entity in memory.
Links between procedures and processes
1. A program may correspond to multiple processes--a program runs multiple times, each time producing a process
2. A process may contain multiple programs--one program depends on multiple other dynamic libraries
B. Concept of threads
1. An execution unit within a process '
2. A schedulable entity in an operating system
3. A sequence of relatively independent control flows in a process
4. Field data at execution and other information required for scheduling
Deep understanding of threads and processes
1. There are multiple threads sharing process resources in a process
2. Threads are scheduled execution units, and processes are not scheduling units
3. Threads cannot exist independently of processes, they can only depend on processes to run.
4. Threads have lifetimes, birth and death.
Any thread can create new threads.
II.Qt Multithreaded Programming
A.Qt directly supports multithreading through QThread
QThread is a cross-platform multithreaded solution.
2. QThread Multithreaded programming in a simple and easy to use way
Key member functions in QThread
1. void run()--Thread body function, used to define thread function (execution flow)
2. void start()--Start function, set thread entry address to run function
3. void terminate()--Mandatory termination of threads
QThread Programming Example
code example
#include #include #include class MyThread : public QThread{protected: void run() { qDebug()