C++11 std::condition_variable: can we pass our lock directly to the notified thread?
问题 I'm learning about C++11 concurrency, where my only prior experience with concurrency primitives was in Operating Systems class six years ago, so be gentle, if you can. In C++11, we can write std::mutex m; std::condition_variable cv; std::queue<int> q; void producer_thread() { std::unique_lock<std::mutex> lock(m); q.push(42); cv.notify_one(); } void consumer_thread() { std::unique_lock<std::mutex> lock(m); while (q.empty()) { cv.wait(lock); } q.pop(); } This works fine, but I'm offended by