#include #include #include #include #include #include typedef boost::coroutines::coroutine< void > coro_t; static void foo( coro_t::push_type& yield, int i ) {} struct Worker { boost::atomic< bool > done; Worker() : done( false) {} void operator()() { while ( ! done) { pending.consume_all( [&]( int i) { coro_t::pull_type( boost::bind( foo, _1, i) ); } ); } } boost::lockfree::queue< int, boost::lockfree::capacity< 1024 > > pending; }; int main( int argc, char * argv[]) { for ( int i = 1; i < 1000; ++i) { Worker workers[2]; boost::thread threads[2] = { boost::thread( boost::ref( workers[0]) ), boost::thread( boost::ref( workers[1]) ) }; workers[0].pending.push(0); workers[1].pending.push(1); workers[0].done = true; workers[1].done = true; threads[0].join(); threads[1].join(); } return EXIT_SUCCESS; }