|
TEC
A lightweight C++ library enabling safe, efficient execution in multithreaded and concurrent systems.
|
A thread-safe signal mechanism for inter-thread synchronization. More...
#include <tec_signal.hpp>
Classes | |
| struct | OnExit |
| Helper struct to signal termination on exit. More... | |
Public Member Functions | |
| Signal () | |
| Constructs a signal in the unsignaled state. | |
| Signal (const Signal &)=delete | |
| Signal (Signal &&)=delete | |
| void | set () |
| Sets the signal to the signaled state and notifies all waiting threads. | |
| void | wait () const |
| Waits indefinitely until the signal is set. | |
| template<typename Duration > | |
| bool | wait_for (Duration dur) const |
| Waits for the signal to be set for a specified duration. | |
A thread-safe signal mechanism for inter-thread synchronization.
This class provides a simple signal implementation using a mutex and condition variable. It allows threads to wait for a signal to be set, either indefinitely or with a timeout. The signal can be set to notify all waiting threads.
|
inline |
Constructs a signal in the unsignaled state.
Initializes the signal with a false flag, indicating it is not signaled.
|
inline |
Sets the signal to the signaled state and notifies all waiting threads.
Updates the signal flag to true in a thread-safe manner and notifies all threads waiting on the condition variable.
|
inline |
Waits indefinitely until the signal is set.
Blocks the calling thread until the signal's flag is set to true. The operation is thread-safe.
Waits for the signal to be set for a specified duration.
Blocks the calling thread until the signal is set or the specified duration elapses. Returns true if the signal was set, false if the timeout occurred.
| Duration | The type of the duration parameter (e.g., std::chrono::milliseconds). |
| dur | The maximum duration to wait for the signal. |