Fans’ questions must be arranged. How can two threads and two mutexes deadlock? The program flow chart is as follows: Program flow chart As shown in the figure above:
[Note] To ensure that the main thread and child thread can obtain the locks mutex1 and mutex2 respectively, each thread must sleep for 1 second after obtaining the lock. Otherwise, after the child thread is created, the main thread still has a certain time slice, and the main thread will apply for the lock mutex2, and a deadlock cannot be formed. Deadlock The source code is as follows
Compile and run From the execution results, we can judge that the main thread and the child thread obtained the mutex locks mutex1 and mutex2 respectively. After sleeping for 1 second, they both wanted to apply for mutex2 and mutex1 respectively, but neither side wanted to release the locks in their hands. The locks have formed a deadlock, and the program has been in a dormant state. Check the threads of the process Check the process ID, which is 4204 Check the thread IDs created by the process: 4204, 4205. This article is reprinted from the WeChat public account "Yikou Linux", which can be followed through the following QR code. To reprint this article, please contact Yikou Linux public account. |
<<: Foreign media: Global investment and deployment in 5G will accelerate in 2020
[[352290]] This article is reprinted from the WeC...
[[188829]] As an application-oriented research fi...
[[341325]] This article is reprinted from the WeC...
This article is reprinted from the WeChat public ...
2019 can be said to be the first year of 5G base ...
They say that in travel, getting to your destinat...
NFV automation and NFV orchestration have overlap...
Labs Guide As a common network device, routers ca...
In the previous article, we mentioned how to surv...
Smart cities collect data from different connecte...
In today's digital economy era, it has become...
From the voice services in the 2G era, to the ris...
China’s 5G licenses have only been issued for a y...
Here is an update on Tencent Cloud's flash sa...
Throughout history, every social transformation, ...