virtual void run(void) { int i, v; for (i=0; i<max; i++) { { locker kk(dmut); dsem.wait(dmut); v = data; } { locker l(outmut); fprintf(stderr, "Got data %s: %d\n", name, v); } thread::sleep(1000); } }
bool take( value_type & va) { mutex::scoped_lock lk( head_mtx_); bool empty = empty_(); if ( ! active_() && empty) return false; if ( empty) { try { while ( active_() && empty_() ) not_empty_cond_.wait( lk); } catch ( fiber_interrupted const&) { return false; } } if ( ! active_() && empty_() ) return false; swap( va, head_->va); pop_head_(); return va; }