Bundle
System support for threads and runtime concurrency
Semaphore
Counting semaphore: a pool of permits. Acquire takes one, waiting while none are left; Release returns one and wakes a waiting thread. Built on a ThreadMutex and a Condition, so a waiting thread sleeps rather than spins.
Example
sem := Semaphore->New(2);
sem->Acquire();
sem->Available()->PrintLine(); # 1
sem->TryAcquire()->PrintLine(); # true
sem->TryAcquire()->PrintLine(); # false
sem->Release();
sem->Release();
sem->Available()->PrintLine(); # 2Operations
Available #
Number of permits available now
method : public : Available() ~ IntReturn
| Type | Description |
|---|---|
| Int | number of permits |
New # constructor
Creates a semaphore
New(permits:Int)Parameters
| Name | Type | Description |
|---|---|---|
| permits | Int | number of permits available at the start (a negative number counts as 0) |