OpenGL Vizserver Reference Page


NAME
vsMutex - Mutual exclusion mechanism

HEADER FILE
#include <vizserver/vsLock.h>

PUBLIC METHOD SUMMARY
vsMutex ( vsLock& lock_);
~vsMutex (  );

CLASS DESCRIPTION
This class exists to allow for mutual exclusion within a block of code. When constructed, the instance locks the lock passed in the constructor. The lock is released when the vsMutex object is destroyed.

The vsMutex is a convenience that allows for automatic lock release when a particular control block is exited (i.e., when returning early from a function or an exception is thrown).

METHOD DESCRIPTIONS

   vsMutex()
vsMutex ( vsLock& lock_);

Acquires the lock_ until the destructor for this instance is invoked (i.e., upon exit of the current scope).

The following is an example of the use of this class.
while (foo < bar) {
    vsMutex(myLock);    // lock the lock
    if (xyz == foo)
        // lock is automatically unlocked on return
        return;
    else if (xyz == 0)
        // lock is automatically unlocked on throw
        throw error;
    else if (foo == 0)
        // lock is automatically unlocked on exit of block
        break;
    ++foo;
    // lock is automatically unlocked on exit of block 
    // due to vsMutex destructor
}
It should be noted that in those cases where the calling thread exits while a vsMutex is active, the lock is not released (since the C++ scope exit rules are not invoked).

   ~vsMutex()
~vsMutex (  );

Releases the lock.