Vaca::Mutex Class Reference

#include <Mutex.h>

Inheritance diagram for Vaca::Mutex:

Vaca::NonCopyable

List of all members.


Detailed Description

An object to synchronize threads using mutual exclusion of critical sections.

This kind of mutex can be used to synchronize multiple threads of the same process. No multiple processes!

Win32 Specific:
This is a CRITICAL_SECTION(W32) wrapper.

See also:
ScopedLock, ConditionVariable, Thread, Critical Section in Wikipedia Mutex in Wikipedia

Public Member Functions

 Mutex ()
 Creates a new mutex.
 ~Mutex ()
 Destroys the mutex.
void lock ()
 Locks the mutex to enter in a critical section.
bool tryLock ()
 Tries to lock the mutex and returns true if it was locked.
void unlock ()
 Unlocks the mutex so another thread can lock it.

Private Attributes

CRITICAL_SECTION m_cs

Constructor & Destructor Documentation

Mutex::Mutex (  ) 

Creates a new mutex.

Win32 Specific:
It uses InitializeCriticalSection(W32).

Mutex::~Mutex (  ) 

Destroys the mutex.

Win32 Specific:
It uses DeleteCriticalSection(W32).


Member Function Documentation

void Mutex::lock (  ) 

Locks the mutex to enter in a critical section.

Locks the mutex if it is free (not locked by another thread) or waits the mutex to be unlocked.

See also:
unlock, ScopedLock, Thread
Win32 Specific:
It uses EnterCriticalSection(W32).

bool Mutex::tryLock (  ) 

Tries to lock the mutex and returns true if it was locked.

See also:
lock
Win32 Specific:
It uses TryEnterCriticalSection(W32).

void Mutex::unlock (  ) 

Unlocks the mutex so another thread can lock it.

You have to unlock a mutex to give access to another thread to enter in the critical section and use the shared resources that this mutex is guarding.

See also:
lock, ScopedLock, Thread
Win32 Specific:
It uses LeaveCriticalSection(W32).


Member Data Documentation

CRITICAL_SECTION Vaca::Mutex::m_cs [private]