Sometimes, there is a requirement to process tasks in a specified time interval. Compared to previous recipes, where we were trying to process tasks in the order of their appearance in the queue, this is a big difference.
Consider the example where we are writing a program that connects two subsystems, one of which produces data packets and the other writes modified data to the disk (something like this can be seen in video cameras, sound recorders, and other devices). We need to process data packets one by one in the specified order, smoothly with a small jitter, and in multiple threads.
Naive approach does not work here:
#include <boost/thread/thread.hpp>
subsystem1 subs1;
subsystem2 subs2;
void process_data() {
while (!subs1.is_stopped()) {
data_packet data = subs1.get_data();
decoded_data d_decoded = decode_data(data);
compressed_data...