Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpMutex::vpScopedLock Class Reference

#include <visp3/core/vpMutex.h>

Public Member Functions

 vpScopedLock (vpMutex &mutex)
 
 ~vpScopedLock ()
 

Detailed Description

Class that allows protection by mutex.

The following example shows how to use this class to protect a portion of code from concurrent access. The scope of the mutex lock/unlock is determined by the constructor/destructor.

#include <visp3/core/vpMutex.h>
int main()
{
vpMutex mutex;
{
// shared var to protect
}
}

Without using vpScopedLock, the previous example would become:

#include <visp3/core/vpMutex.h>
int main()
{
vpMutex mutex;
{
mutex.lock();
// shared var to protect
mutex.unlock()
}
}

More examples are provided in Tutorial: How to use multi-threading capabilities.

See Also
vpMutex
Examples:
grabRealSense.cpp, testForceTorqueAti.cpp, testRealSense.cpp, tutorial-face-detector-live-threaded.cpp, tutorial-grabber-opencv-threaded.cpp, and tutorial-grabber-v4l2-threaded.cpp.

Definition at line 163 of file vpMutex.h.

Constructor & Destructor Documentation

vpMutex::vpScopedLock::vpScopedLock ( vpMutex mutex)
inline

Constructor that locks the mutex.

Definition at line 178 of file vpMutex.h.

References vpMutex::lock().

vpMutex::vpScopedLock::~vpScopedLock ( )
inline

Destructor that unlocks the mutex.

Definition at line 184 of file vpMutex.h.

References vpMutex::unlock().