Game Development Reference
In-Depth Information
};
class SomeContainer: public iObject
{
A list of garbage-collected elements:
std::vector< clPtr<SomeElement> > Elements;
};
See also
F Implementing asynchronous task queues
Implementing asynchronous task queues
We want to execute a list of tasks asynchronously from the main thread but retain their order
relative to each other. Let's implement a queue for such tasks.
Getting ready
We need mutexes and smart pointers from the previous recipes to do this, since the queue
needs synchronization primitives to keep its internal data structures consistent, and it needs
smart pointers to prevent tasks from leaking.
How to do it...
1.
The interface for tasks we want to put into the worker thread is as follows:
class iTask: public iObject
{
public:
iTask()
: FIsPendingExit(false)
, FTaskID(0)
, FPriority(0) {};
2.
The Run() method contains a payload of our task. It is where all the useful work
is done:
virtual void Run() = 0;
 
Search WWH ::




Custom Search