PLCnext API Documentation  22.9.0.33
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Friends | List of all members
Arp::System::Commons::Threading::Mutex Class Reference

Mutual exclusion object to prevent data from concurrent modifications. More...

#include <Mutex.hpp>

Public Member Functions

 Mutex (bool recursive=true)
 Constructs and initializes an Mutex instance. More...
 
 Mutex (Mutex &&arg)
 Move contructor More...
 
virtual ~Mutex (void)
 Destructs this instance and frees all resources. More...
 
void Lock (void)
 Tries to acquire the lock. More...
 
void Unlock (void)
 Releases the lock. More...
 
bool TryLock (void)
 Like Lock but returns immediately if the lock is already obtained by another thread. More...
 

Friends

class ConditionVariable
 

Detailed Description

Mutual exclusion object to prevent data from concurrent modifications.

Instances of this class has two states: locked and unlocked. As soon as a call to Lock() returns the calling thread has acquired the lock and every other thread that also calls Lock() is suspended until the first thread calls Unlock(). Thus objects uses instances of this class can prevent their data from concurrent modification from different threads.

Constructor & Destructor Documentation

◆ Mutex() [1/2]

Arp::System::Commons::Threading::Mutex::Mutex ( bool  recursive = true)

Constructs and initializes an Mutex instance.

◆ Mutex() [2/2]

Arp::System::Commons::Threading::Mutex::Mutex ( Mutex &&  arg)

Move contructor

◆ ~Mutex()

virtual Arp::System::Commons::Threading::Mutex::~Mutex ( void  )
virtual

Destructs this instance and frees all resources.

Member Function Documentation

◆ Lock()

void Arp::System::Commons::Threading::Mutex::Lock ( void  )

Tries to acquire the lock.

If the lock is already taken by another thread, the calling thread blocks until the lock becomes available again, i.e. the thread currently obtaining the lock calls Unlock.

◆ TryLock()

bool Arp::System::Commons::Threading::Mutex::TryLock ( void  )

Like Lock but returns immediately if the lock is already obtained by another thread.

Returns
If the lock is acquired successfully this method returns "true". If the lock is already obtained by another thread "false" is returned.

◆ Unlock()

void Arp::System::Commons::Threading::Mutex::Unlock ( void  )

Releases the lock.


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