Created
January 9, 2020 06:36
-
-
Save arcticmatt/d7de81bf244cda0b35832070f315f587 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void lockMutexGood(bool shouldThrow) { | |
std::cout << "Locking mutex with scoped_lock..." << std::endl; | |
std::scoped_lock lock(globalMutex); | |
std::cout << "Mutex is locked!" << std::endl; | |
if (shouldThrow) { | |
std::cout << "Throwing exception" << std::endl; | |
throw 1; | |
} | |
} | |
void lockMutexGoodExample() { | |
try { | |
lockMutexGood(true); | |
} catch (...) { | |
std::cout << "Caught exception" << std::endl; | |
} | |
lockMutexGood(false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment