Encapsulation of an critical section. Unlocking is guaranteed when the Lock goes out of scope, even on exception.
Remarks:
Lock is a scope class, you need to mark Lock object as scope :
Mutex m = new Mutex;
//..
{
scope Lock l = new Lock(m);
// Critical section
} // End of critical (Destructor called and mutex unlocked)
//..
- this(Mutex m);
- Construct the lock and lock the mutex