C++
C#
VB
JScript
All

Class mutex


Copyright (C) 2005 IENT-RWTH Aachen

Protects shared data structures from concurrent modifications

Remarks

Prefer the use of a scoped_lock rather than explicitly calling the acquire and release methods.

Groups

Constructors
Method mutex

Builds an instance of the object

Multithreading Functions
Method acquire

Waits until a lock can be acquired

Method release

Releases the lock

Method try_acquire

Returns true if it can immediately acquire a lock, else returns false

Destructors
Method ~mutex

Destroys the object

Example

int var;
typedef gmt::mutex mutex_type;
mutex_type mut;

inline set_var(int x)
{
  mutex_type::scoped_lock lock(mut);
  var=x;
};

See Also

spin_mutex, condition_mutex, scoped_lock