Libthreadar  1.4.0
Public Member Functions | Protected Attributes | List of all members
libthreadar::mutex Class Reference

Wrapper around the Posix pthread_mutex_t C objects. More...

#include <mutex.hpp>

Inherited by libthreadar::condition.

Public Member Functions

 mutex ()
 constructor
 
 mutex (const mutex &ref)=delete
 no copy constructor
 
 mutex (mutex &&ref)=default
 no move constructor
 
mutexoperator= (const mutex &ref)=delete
 no assignment operator
 
mutexoperator= (mutex &&ref) noexcept=default
 no move operator
 
virtual ~mutex ()
 destructor
 
void lock ()
 lock the mutex More...
 
void unlock ()
 unlock the mutex More...
 
bool try_lock ()
 Tells whether calling lock() would currently suspend the caller or not. More...
 

Protected Attributes

pthread_mutex_t mut
 

Detailed Description

Wrapper around the Posix pthread_mutex_t C objects.

To protect a data against concurrent access by different threads each thread has to call the lock() method before and unlock() method after accessing that data. If another thread is already accessing that data calling lock() will suspended the calling thread up to the time the thread accessing the data calls unlock()

Examples
/doc/examples/thread_example.cpp.

Definition at line 56 of file mutex.hpp.

Member Function Documentation

◆ lock()

void libthreadar::mutex::lock ( )

lock the mutex

Note
if another thread has called lock() and not yet called unlock(), the calling thread is suspended up to the time the mutex is released by a call to unlock().

Referenced by libthreadar::tampon< T >::has_readable_block_next(), and libthreadar::tampon< T >::is_empty().

◆ try_lock()

bool libthreadar::mutex::try_lock ( )

Tells whether calling lock() would currently suspend the caller or not.

Returns
true if lock is acquired false if mutex was already locked

◆ unlock()

void libthreadar::mutex::unlock ( )

unlock the mutex

Note
if one or more threads are suspended on that mutex, a single thread suspended is then awaken and returns from its call to lock().

Referenced by libthreadar::tampon< T >::has_readable_block_next(), and libthreadar::tampon< T >::is_empty().


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