Semaphore

A Semaphore implementation.

A semaphore manages an internal counter which is decremented by each $(D_PSYMBOL acquire()) call and incremented by each $(D_PSYMBOL release()) call. The counter can never go below zero; when $(D_PSYMBOL acquire()) finds that it is zero, it blocks, waiting until some other thread calls $(D_PSYMBOL release()).

The optional argument gives the initial value for the internal counter; it defaults to 1.

This class is not thread safe.

Constructors

this
this(EventLoop eventLoop, size_t value)
Undocumented in source.

Members

Functions

acquire
bool acquire()

Acquire a semaphore.

release
void release()

Release a semaphore, incrementing the internal counter by one. When it was zero on entry and another coroutine is waiting for it to become larger than zero again, wake up that coroutine.

toString
string toString()
Undocumented in source. Be warned that the author may not have intended to support it.

Properties

locked
bool locked [@property getter]

Returns $(D_KEYWORD true) if semaphore can not be acquired immediately.

Meta