Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
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>
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
int main()
{
vpMutex mutex;
{
// shared var to protect
}
}
Class that allows protection by mutex.
Definition vpMutex.h:186
void lock()
Definition vpMutex.h:104
vpMutex()
Definition vpMutex.h:86

Without using vpScopedLock, the previous example would become:

#include <visp3/core/vpMutex.h>
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
int main()
{
vpMutex mutex;
{
mutex.lock();
// shared var to protect
mutex.unlock()
}
}
void unlock()
Definition vpMutex.h:120
See also
vpMutex

Definition at line 185 of file vpMutex.h.

Constructor & Destructor Documentation

◆ vpScopedLock()

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

Constructor that locks the mutex.

Definition at line 204 of file vpMutex.h.

References vpMutex::vpMutex().

◆ ~vpScopedLock()

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

Destructor that unlocks the mutex.

Definition at line 206 of file vpMutex.h.