On Mon, Sep 9, 2013 at 2:35 PM, firespot71
But am I correct that both variants are safe, so neither deadlocks nor races may occur under any circumstances (ignore any issues outside of the code snippet above)? Once the notify-signal is issued each waiting thread needs to acquire the lock, and hence they get the lock strictly sequentially. I.e. most of them have to wait anyway while some other thread has the mutex locked. Variant 1 has the advantage of 'bundling' the continuation and notification signal, and it also notifies other threads at the earliest possible point - of course given if it's technically allowed to do it while still locking the mutex, which I think is ok but not 100% sure.
Thomas
Both variants are safe, but normal usage would say that variant 2 is at least as efficient as variant 1. By normal usage I mean that whichever thread is notified will need to acquire the lock before it can do anything useful. Brian