Sane C++ Libraries
C++ Platform Abstraction Libraries
SC::Mutex Struct Reference

A native OS mutex to synchronize access to shared resources. More...

#include <Threading.h>

Public Member Functions

 Mutex (const Mutex &)=delete
 
 Mutex (Mutex &&)=delete
 
Mutexoperator= (const Mutex &)=delete
 
Mutexoperator= (Mutex &&)=delete
 
void lock ()
 
void unlock ()
 

Friends

struct ConditionVariable
 

Detailed Description

A native OS mutex to synchronize access to shared resources.

Example:

Mutex mutex;
int globalVariable = 0;
Thread thread1;
auto thread1Func = [&](Thread& thread)
{
thread.setThreadName(SC_NATIVE_STR("Thread1"));
mutex.lock();
globalVariable++;
mutex.unlock();
};
SC_TEST_EXPECT(thread1.start(thread1Func));
Thread thread2;
auto thread2Func = [&](Thread& thread)
{
thread.setThreadName(SC_NATIVE_STR("Signaling2"));
mutex.lock();
globalVariable++;
mutex.unlock();
};
SC_TEST_EXPECT(thread2.start(thread2Func));
SC_TEST_EXPECT(thread1.join());
SC_TEST_EXPECT(thread2.join());
SC_TEST_EXPECT(globalVariable == 2);
#define SC_TEST_EXPECT(e)
Records a test expectation (eventually aborting or breaking o n failed test)
Definition: Testing.h:113

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