UNISA Chatter – Design patterns in C++ Part 5: Multi-Threading with QT
See UNISA – Summary of 2010 Posts for a list of related UNISA posts. Continued from UNISA Chatter – Design patterns in C++ Part 4: Widgets … getting started with the QT User Interface.
IMPORTANT POINT: It is important to emphasize that the intent of these posts are to share my learning's as I dig through the last three subjects of my part-time UNISA studies. The posts by no means promote concepts or technologies … they are pure information sharing for fellow students … although the highlight that we explore more technologies and concepts that we typically prefer :)
QT and Environment Summary
The following is a summary of findings as I worked through the course related book. See the summary post for details on the book.
Terminology | Description | Example |
QProcess | Class that is used to spawn another process. Some important notes:
|
class MyProcess : QProcess { Q_OBJECT … } |
QThread | Class used to spawn another thread. Some important notes:
|
class MyThread : QThread { Q_OBJECT …. } |
QMutex | Used for mutual exclusion, allowing threads to protect (lock) an object or sections of code. |
|
QWaitCondition | Combined with QMutex, QWaitCondition can be used to place threads into non-busy block state and wait to be woken up by another thread. |
|
QSemaphore | QSemaphore is used to lock more that one resource and to ensure that threads only lock available resources. |
Here is the simple example application I created … two threads creating hypothetical stock prices:
Shout if you would like the C++ source code.