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

php - Hide output during test execution -

javascript - Migrate custom AngularJS filter from 1.2.28 to 1.4.x -

Update Magento products with multiple images -