mutex m; condition_variable not_empty; condition_variable not_full; void producer() { while(true) { produce something, store in foo unique_lock lock(m); while (buffer.full()) not_full.wait(lock); buffer.push(foo); lock.unlock(); not_empty.notify_all(); } } void consumer() { while(true) { unique_lock lock(m); while (buffer.empty()) not_empty.wait(lock); foo = buffer.top(); buffer.pop(); lock.unlock(); not_full.notify_all(); use foo } }