void withdrawer() { unique_lock lock(m); // m.lock(); done as part of above constructor // note: you can specify additional parameter and "deferred_lock" to avoid // this while (balance < 100) { cond.wait(lock); } withdraw(100); m.unlock(); } void depositer() { m.lock(); deposit(100); m.unlock(); cond.notify_one(); }