SbThreadAutoLock Class Reference
[Threads]

VSG extension Provides reliable unlocking of a mutex. More...

#include <Inventor/threads/SbThreadAutoLock.h>

List of all members.

Public Member Functions

 SbThreadAutoLock (SbThreadMutex *mutex)
 SbThreadAutoLock (SbThreadMutex &mutex)

Detailed Description

VSG extension Provides reliable unlocking of a mutex.

This class provides reliable unlocking of a mutex.

An SbThreadMutex object must be created separately. The address of the mutex object is passed to the constructor, which locks the mutex and saves a reference to the mutex object. The autolock object should be created on the stack, so each thread will have its own autolock. The destructor automatically unlocks the mutex.

Because the autolock object is created on the stack, it avoids the need to explicitly unlock the mutex at every point of exit from the function (a common source of errors). The mutex will be unlocked when the autolock goes out of scope.

Example:

      // myClass contains a Mutex object named m_mutex
      void myClass::someFunction() 
      {
         // m_mutex is a ptr to an existing SbThreadMutex object
         SbThreadAutoLock dummyName( m_mutex );
         ... other code ...
      } // mutex automatically unlocked

SEE ALSO

SbThread, SbThreadAutoReadLock, SbThreadAutoWriteLock, SbThreadBarrier, SbThreadMutex, SbThreadRWMutex


Constructor & Destructor Documentation

SbThreadAutoLock::SbThreadAutoLock ( SbThreadMutex mutex  )  [inline]

Creates a mutex "autolock" object and automatically calls the mutex lock method.

The mutex will be automatically unlocked when the autolock object is destroyed.

SbThreadAutoLock::SbThreadAutoLock ( SbThreadMutex mutex  )  [inline]

The documentation for this class was generated from the following file:

Open Inventor Toolkit reference manual, generated on 4 Sep 2023
Copyright © Thermo Fisher Scientific All rights reserved.
https://www.openinventor.com/