A while ago, I wrote a numberProgram. A total of two functions are implemented: 1. start/stop of running; 2. Start computing again. The START/pause part must be suspended to find the prime number of threads. But I read the document several times and found that there was no function to suspend the thread ......
After searching for a long time, I found that the POSIX thread model did not include the suspension function. If a ready-made thread is suspended, the resources occupied by the thread cannot be released. As long as the thread is suspended, the resources it occupies remain in the occupied State. Therefore, the POSIX model handed this right to the operating system designer.
The solution is to use the lock.
Boost and QT both use the POSIX thread model, so they do not have to suspend functions.
Add on:
After practice, we found that qmutex of QT is not allowed in the thread To unlock the qmutex object locked in thread a in thread B. So with my current knowledge, there is no method for suspending threads in QT. You can only determine whether to allow running at each running time.
The boost lock is acceptable, but its actual running status can only be described as "weird ......
The specific solution is still in practice!