103. Destructors-I

Question.2

A MutexLock class acquires in constructor and releases in destructor:

class MutexLock {
   Mutex& mtx;
public:
   MutexLock(Mutex& m) : mtx(m) { mtx.lock(); }
   ~MutexLock() { mtx.unlock(); }
};

void update_data() {
   MutexLock guard(data_mutex);
   if (error) return;  // Early exit
   process();
}

Is the mutex released on the early return?

Need Help? Refer to the Quick Guide below

Select Answer