FRI-OS
Public Member Functions | List of all members
mutex::lock Class Reference

Class locking a mutex on construction and unlocking on destruction. More...

#include <frios/posix/threads/mutex.hpp>

Inheritance diagram for mutex::lock:
Inheritance graph
[legend]

Public Member Functions

 lock (mutex &mutex)
 Locks the specified mutex. More...
 
 ~lock (void)
 Unlocks the mutex locked in the constructor.
 

Detailed Description

Class locking a mutex on construction and unlocking on destruction.

Instances of the lock class lock a specified mutex when they are constructed and unlock it when they are destroyed.

Example of usage:

// a variable shared by multiple threads
int shared_i;
// a mutex for synchronizing access to shared_i
mutex mutex_i;
// synchronized function returning the value of shared_i
int get_shared_i(void)
{
mutex::lock l(mutex_i);
return shared_i;
}
// synchronized function setting the value of shared_i
void set_shared_i(int new_i)
{
mutex::lock l(mutex_i);
shared_i = new_i;
}
Examples:
example/posix/threads-bingo_detached.cpp, and example/posix/threads-producer_consumer.cpp.

Constructor & Destructor Documentation

lock ( mutex mutex)

Locks the specified mutex.

Exceptions
lock_error

The documentation for this class was generated from the following file: