Skip to content

Instantly share code, notes, and snippets.

@arcticmatt
Created January 9, 2020 06:36
Show Gist options
  • Save arcticmatt/d7de81bf244cda0b35832070f315f587 to your computer and use it in GitHub Desktop.
Save arcticmatt/d7de81bf244cda0b35832070f315f587 to your computer and use it in GitHub Desktop.
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