Hacker News new | ask | show | jobs
by DerKommissar 4479 days ago

  mutex.lock();
  doStuff(); /*throws an exception, mutex is never unlocked*/
  mutex.unlock();

  ScopedLock lock(mutex);
  doStuff(); /*mutex unlocked by destructor in all cases*/
It guarantees that resources are freed no matter how the scope exits.