I would like to have something like a tbb::task_group but with the difference of guaranteed in order execution, e.g.
serial_task_group tasks;
tasks.run([]{std::cout << 1;});
tasks.run([]{std::cout << 2;});
tasks.run([]{std::cout << 3;});
tasks.wait();
// guaranteed output: 123
Any suggestions as to how one could achieve this using tbb?
Currently I have an explicit thread that just executes from a queue using a condition variable. However, the problem with using a queue is how I would go about guaranteeing
that only exactly one task is active in the task_group.
(Disclosure: I work on Intel Threading Building Blocks at Intel.)
As was suggested in another answer, you can use the flow graph to do something like this. The code for your example using the flow graph would look something like: