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

An automatically reset event object to synchronize two threads. More...

#include <Threading.h>

Public Member Functions

void wait ()
 Waits on a thread for EventObject::signal to be called from another thread. More...
 
void signal ()
 Unblocks another thread, waiting on EventObject::wait. More...
 

Public Attributes

bool autoReset = true
 

Detailed Description

An automatically reset event object to synchronize two threads.


Example:

EventObject eventObject;
Thread threadWaiting;
auto waitingFunc = [&](Thread& thread)
{
thread.setThreadName(SC_NATIVE_STR("Thread waiting"));
eventObject.wait();
report.console.printLine("After waiting");
};
SC_TEST_EXPECT(threadWaiting.start(waitingFunc));
Thread threadSignaling;
auto signalingFunc = [&](Thread& thread)
{
thread.setThreadName(SC_NATIVE_STR("Signaling thread"));
report.console.printLine("Signal");
eventObject.signal();
};
SC_TEST_EXPECT(threadSignaling.start(signalingFunc));
SC_TEST_EXPECT(threadWaiting.join());
SC_TEST_EXPECT(threadSignaling.join());
// Prints:
// Signal
// After waiting
#define SC_TEST_EXPECT(e)
Records a test expectation (eventually aborting or breaking o n failed test)
Definition: Testing.h:113

Member Function Documentation

◆ signal()

void SC::EventObject::signal ( )

Unblocks another thread, waiting on EventObject::wait.

◆ wait()

void SC::EventObject::wait ( )

Waits on a thread for EventObject::signal to be called from another thread.


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