In the previous section, we defined clWorkerThread
and iTask
classes that allow us to execute lengthy operations outside of the UI thread in C++ code. The final thing we need to organize a responsive interface is the ability to pass around events across different threads. To do this, we need a callable interface, which can encapsulate the parameters passed to a method, and a thread-safe mechanism to pass such capsules across the threads.
A nice candidate for such a capsule is std::packaged_task
, which is not supported in the most recent MinGW toolchain. Therefore, we will define our own lightweight reference-counted abstract class iAsyncCapsule
, which implements a single method, Invoke()
:
class iAsyncCapsule: public iIntrusiveCounter { public: virtual void Invoke() = 0; };
We call a prioritized collection of iAsyncCapsule
instances wrapped in clPtr
an asynchronous queue. The clAsyncQueue
class implements the DemultiplexEvents()
method, which...