reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofTypes.h File Reference
#include "ofConstants.h"
#include <mutex>

Go to the source code of this file.

Typedefs

typedef std::mutex ofMutex
 A typedef for a cross-platform mutex.
 
typedef std::unique_lock< std::mutex > ofScopedLock
 A typedef for a cross-platform scoped mutex.
 
template<typename T >
using ofPtr = std::shared_ptr< T >
 

Typedef Documentation

◆ ofMutex

typedef std::mutex ofMutex

A typedef for a cross-platform mutex.

Deprecated:
Please use std::mutex instead of ofMutex. See also the note below.

A mutex is used to lock data when it is accessible from multiple threads. Locking data with a mutex prevents data-races, deadlocks and other problems associated with concurrent access to data.

The mutex can be locked with a call to ofMutex::lock(). All calls to ofMutex::lock() must be paired with a call to ofMutex::unlock().

ofMutex myMutex; // Your member mutex.
int mySharedData; // Your member shared data.
// ...
// A method to modify some shared data.
void modifyMySharedData() {
myMutex.lock(); // Lock the mutex.
mySharedData++; // Modify the shared data.
myMutex.unlock(); // Unlock the mutex;
}
std::mutex ofMutex
A typedef for a cross-platform mutex.
Definition ofTypes.h:42
Note
Currently ofMutex is a typedef for std::mutex. This is done to preserve backwards compatibility. Please use std::mutex for new code.
See also
http://www.cplusplus.com/reference/mutex/mutex/
ofScopedLock

◆ ofPtr

template<typename T >
using ofPtr = std::shared_ptr<T>

◆ ofScopedLock

typedef std::unique_lock<std::mutex> ofScopedLock

A typedef for a cross-platform scoped mutex.

Deprecated:
Please use std::unique_lock<std::mutex> instead of ofScopedLock. See also the note below.

Normally ofMutex requres explicit calls to ofMutex::lock() and ofMutex::unlock() to lock and release the mutex. Sometimes, despite best efforts, developers forget to unlock a mutex, leaving the data inaccessible. ofScopedLock makes ofMutex easier to use by calling ofMutex::unlock when the scoped lock's destructor is called. Since the destructor is called when a variable goes out of scope, we call this a "scoped lock". A "scoped lock" is sometimes known as a "lock guard" as well.

ofScopedLock is used to lock and unlock an existing ofMutex.

ofMutex myMutex; // Your member mutex.
int mySharedData; // Your member shared data.
// ...
// A method to modify some shared data.
void modifyMySharedData() {
ofScopedLock lock(myMutex); // Lock the mutex.
mySharedData++; // Modify the shared data.
// `lock` will unlock the mutex when it goes out of scope.
}
std::unique_lock< std::mutex > ofScopedLock
A typedef for a cross-platform scoped mutex.
Definition ofTypes.h:80
Warning
Currently ofScopedLock is a typedef for std::unique_lock<std::mutex>. This is done to preserve backwards compatibility. Please use std::unique_lock<std::mutex> for new code.
See also
http://en.cppreference.com/w/cpp/thread/unique_lock
ofMutex