Main Page   Class Hierarchy   Alphabetical List   Compound List   Compound Members  

util::Mutex Class Reference

#include <Mutex.h>

Inheritance diagram for util::Mutex:

util::Object List of all members.

Detailed Description

Mutual exclusion lock.

Concurrent threads that must synchronize their access to shared variables need to use a mutex lock to prevent mixups.

Public Methods

 Mutex (int type=PTHREAD_MUTEX_RECURSIVE) throw (MutexException&)
 Create a new mutual exclusion lock.

 Mutex (const Mutex &other)
 Create a copy of a mutex.

 ~Mutex ()
void lock (void) throw (MutexException&)
 Lock a mutex.

void tryToLock (void) throw (MutexException&)
 Lock a mutex.

void unlock (void) throw (MutexException&)
 Release the mutex.

Mutex & operator= (const Mutex &other)
 Copy a mutex.

Constructor & Destructor Documentation

util::Mutex::Mutex int    type = PTHREAD_MUTEX_RECURSIVE throw (MutexException&)

Create a new mutual exclusion lock.

The type of the mutex can be one of the predefined constants in pthread.h, i.e. PTHREAD_MUTEX_{NORMAL,RECURSIVE,ERRORCHECK,DEFAULT}. See the unix man page "pthread_mutex_settype" for details.

Member Function Documentation

void util::Mutex::lock void    throw (MutexException&)

Lock a mutex.

When a mutex is locked by a thread, a locking attempt by another thread cannot succeed until the lock is released. This method blocks until the mutex is available.

MutexException  & if an error occurs

void util::Mutex::tryToLock void    throw (MutexException&)

Lock a mutex.

This method is identical to lock except that the call terminates immediately if the mutex is alredy locked.

MutexException  if the mutex is locked or an error occurs

void util::Mutex::unlock void    throw (MutexException&)

Release the mutex.

MutexException  & if an error occurs

The documentation for this class was generated from the following files:
Documentation generated on 11.09.2003 with Doxygen.
The documentation is copyrighted material.
Copyright © Topi Mäenpää 2003. All rights reserved.