Let's call the functional object that takes no arguments (a task, for short).
typedef boost::function<void()> task_t;
Now, imagine a situation where we have threads that post tasks and threads that execute posted tasks. We need to design a class that can be safely used by both types of those threads. This class must have functions for:
- Getting a task or waiting for a task till it is posted by another thread
- Checking and getting a task if we have one (returning an empty task if no tasks remain)
- Posting tasks
Make sure that you feel comfortable with boost::thread
or std::thread
, know basics of mutexes, and are aware of boost::function
or std::function
.