2014-07-09 19:33 GMT+02:00 Benedek Thaler
Currently, I'm experimenting with coroutines, I think (hope) there is a way we could provide an interface like this:
void duplicate(int input, queue_back<int>& output) { output.push_or_yield(input); output.push_or_yield(input); }
push_or_yield enqueues the element, or if the queue is full: the coroutine yields and tries to enter the monitor of the downstream task. If it's already taken, pick another task. If there is no such task, block until a task becomes available. (or spin on the previous task a bit)
that's exactly what boost.fibers provide (fibers are coroutines + scheduler + synch. classes). a fiber gets suspended if it calls bounded_queue<>::push() and the queue if full or (un)bounded_queue<>::pop() if the queue is empty. the hosting thread is not blocked an can execute other tasks in the mean time.