Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
UppHub
Status & Roadmap
FAQ
Authors & License
Forums
Funding U++
Search on this site











SourceForge.net Logo

SourceForge.net Logo

GitHub Logo

Discord Logo

StaticSemaphore

 

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.

 

 

Public Method List

 

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.

 

 

Constructor detail

 

Semaphore()

Initializes internal counter to 0.

 

 

 

 

StaticSemaphore

 

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.

 

 

Public Method List

 

Semaphore& Get()

operator Semaphore&()

Returns the Semaphore instance.

 


 

void Wait()

void Release()

Call respective methods of Semaphore instance.

 

 

Do you want to contribute?