Agustín K-ballo Bergé wrote:
Alas pthread specifies different semantics than the standard library, and there you are actually expected to hold the lock if you want predictable scheduling.
I don't think that's true. The ability to notify without holding the lock comes from pthreads. It's not a C++ invention, it's a pthread invention; you're most definitely not expected to hold the lock. It's also more efficient because otherwise the awakened thread would immediately block on the mutex.
I hear pthread won't actually wake up any threads then (which wouldn't be able to make progress otherwise), but rather switch them from waiting on the cv to waiting on the mutex to avoid useless context switches; when the mutex is finally unlocked the thread will finally wake up.
Some pthreads implementations supposedly have this optimization, but not all; and if you notify without holding the mutex, the thread would proceed immediately.