class Semaphore
Well known multithreading synchronization tool. In U++, it is primarily used to block and release thread execution. Semaphore has an internal counter, initially initialized to zero. Wait operation blocks thread execution as long as counter is zero, then decreases it by one. Release operation increases counter by 1.
bool Wait(int timeout_ms = -1)
If internal semaphore counter is zero, waits (blocks calling thread) until some other thread increases this counter by 1 calling the Release method or until timeout_ms milliseconds elapses. Before returning, decreases counter by 1. Negative value for timeout_ms means the waiting time is unlimited.
void Release()
Increases internal counter by 1.
Semaphore()
Initializes internal counter to 0.
class StaticSemaphore
Variant of Semaphore that can be used as static or global variable without the need of initialization - it has no constructor and correctly performs the first initialization when any of methods is called. That avoids problems with initialization order or multithreaded initialization issues.
Semaphore& Get()
operator Semaphore&()
Returns the Semaphore instance.
void Wait()
void Release()
Call respective methods of Semaphore instance.
|