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

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -