Visual Servoing Platform  version 3.3.0
vpMutex::vpScopedLock Class Reference

#include <vpMutex.h>

Public Member Functions

 vpScopedLock (vpMutex &mutex)
 
virtual ~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, tutorial-face-detector-live-threaded.cpp, tutorial-grabber-opencv-threaded.cpp, and tutorial-grabber-v4l2-threaded.cpp.

Definition at line 169 of file vpMutex.h.

Constructor & Destructor Documentation

◆ vpScopedLock()

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

Constructor that locks the mutex.

Definition at line 184 of file vpMutex.h.

◆ ~vpScopedLock()

virtual vpMutex::vpScopedLock::~vpScopedLock ( )
inlinevirtual

Destructor that unlocks the mutex.

Definition at line 186 of file vpMutex.h.

vpMutex::unlock
void unlock()
Definition: vpMutex.h:110
vpMutex::lock
void lock()
Definition: vpMutex.h:94
vpMutex
Definition: vpMutex.h:73
vpMutex::vpScopedLock
Class that allows protection by mutex.
Definition: vpMutex.h:169