Poco::Mutex Class Reference

#include <Mutex.h>

Inheritance diagram for Poco::Mutex:

Inheritance graph
[legend]
Collaboration diagram for Poco::Mutex:

Collaboration graph
[legend]

Detailed Description

A Mutex (mutual exclusion) is a synchronization mechanism used to control access to a shared resource in a concurrent (multithreaded) scenario. Mutexes are recursive, that is, the same mutex can be locked multiple times by the same thread (but, of course, not by other threads). Using the ScopedLock class is the preferred way to automatically lock and unlock a mutex.

Definition at line 88 of file Mutex.h.


Public Types

typedef Poco::ScopedLock< MutexScopedLock

Public Member Functions

 Mutex ()
 ~Mutex ()
 creates the Mutex.
void lock ()
 destroys the Mutex.
void lock (long milliseconds)
 Locks the mutex. Blocks if the mutex is held by another thread.
bool tryLock ()
 Locks the mutex. Blocks up to the given number of milliseconds if the mutex is held by another thread. Throws a TimeoutException if the mutex can not be locked within the given timeout.
bool tryLock (long milliseconds)
 Tries to lock the mutex. Returns false immediately if the mutex is already held by another thread. Returns true if the mutex was successfully locked.
void unlock ()
 Locks the mutex. Blocks up to the given number of milliseconds if the mutex is held by another thread. Returns true if the mutex was successfully locked.

Private Member Functions

 Mutex (const Mutex &)
 Unlocks the mutex so that it can be acquired by other threads.
Mutexoperator= (const Mutex &)

Member Typedef Documentation

Definition at line 99 of file Mutex.h.


Constructor & Destructor Documentation

Poco::Mutex::Mutex (  ) 

Definition at line 80 of file Mutex.cpp.

Poco::Mutex::~Mutex (  ) 

creates the Mutex.

Definition at line 85 of file Mutex.cpp.

Poco::Mutex::Mutex ( const Mutex  )  [private]

Unlocks the mutex so that it can be acquired by other threads.


Member Function Documentation

void Poco::Mutex::lock (  )  [inline]

destroys the Mutex.

Definition at line 202 of file Mutex.h.

References Poco::MutexImpl::lockImpl().

void Poco::Mutex::lock ( long  milliseconds  )  [inline]

Locks the mutex. Blocks if the mutex is held by another thread.

Definition at line 208 of file Mutex.h.

References Poco::MutexImpl::tryLockImpl().

bool Poco::Mutex::tryLock (  )  [inline]

Locks the mutex. Blocks up to the given number of milliseconds if the mutex is held by another thread. Throws a TimeoutException if the mutex can not be locked within the given timeout.

Performance Note: On most platforms (including Windows), this member function is implemented using a loop calling (the equivalent of) tryLock() and Thread::sleep(). On POSIX platforms that support pthread_mutex_timedlock(), this is used.

Definition at line 215 of file Mutex.h.

References Poco::MutexImpl::tryLockImpl().

bool Poco::Mutex::tryLock ( long  milliseconds  )  [inline]

Tries to lock the mutex. Returns false immediately if the mutex is already held by another thread. Returns true if the mutex was successfully locked.

Definition at line 221 of file Mutex.h.

References Poco::MutexImpl::tryLockImpl().

void Poco::Mutex::unlock (  )  [inline]

Locks the mutex. Blocks up to the given number of milliseconds if the mutex is held by another thread. Returns true if the mutex was successfully locked.

Performance Note: On most platforms (including Windows), this member function is implemented using a loop calling (the equivalent of) tryLock() and Thread::sleep(). On POSIX platforms that support pthread_mutex_timedlock(), this is used.

Definition at line 227 of file Mutex.h.

References Poco::MutexImpl::unlockImpl().

Mutex& Poco::Mutex::operator= ( const Mutex  )  [private]


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

SourceForge.net Logo
Project space on SourceForge.net