Even though multithreading makes processes run asynchronously, there will be times where threads must be stopped and wait for other threads. This usually happens when both threads are modifying the same variable simultaneously. It is common to force threads to wait for one another to protect shared resources, such as data. Qt 5 also provides both low-level methods and high-level mechanisms to synchronize threads.
We will continue to use the code from the previous example project since we have already established a working program with multithreading:
- Open up myworker.h and add the following header: