Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: extra unlock for if no errors occur

...

Code Block
bgColor#ccccff
langc
#include <mutex>

void manipulate_shared_data(std::mutex &pm) {
  pm.lock();
  try {
    // Perform work on shared data.
  } catch (...) {
    pm.unlock();
    throw;
  }
  pm.unlock(); // in case no exceptions occur
}

Compliant Solution (Lock Object)

...