stl - unlocking std::unique_lock without destroying it -
if create unique_lock below, can unlock without destroying or getting out of scope? in other words safe/acceptable?
std::mutex queuemutex; // understanding locks mutex std::unique_lock<std::mutex> lk(queuemutex); { // critical section } // unlocking properly, or have pop stack? lk.unlock();
thx!
it safe , acceptable, calling unlock()
unlock mutex , make unique_lock
forget not unlock again in dtor.
having said that, scoping preferable in cases readability because if function/scope long , unlock
inside if
or conditional construct might hard reader follow.
Comments
Post a Comment