2.13.9Class SyncCounter

Implements a synchronization counter (semaphore).

Class SyncCounter( [count] )
count Initial counter value (defaults to 0).

This class implements a synchronization counter, commonly known as "semaphore", which provides the following behavior:

- If the counter is greater than zero, the item can be acquired, and the counter is atomically decremented.

We have adopted the "counter" name rather than the more common "semaphore" to avoid confusion with the Semaphore class used for coroutines, and also because the post semantic is merged with the release method.

The counter is created with an initial count that defaults to zero; this means that the first thread trying to acquire this structure will block until a post or release is issued.

If a positive interger is given as count, then the same amount of threads will be able to acquire the semaphore before one thread being blocked.

Methods
postReleases the counter or increases the counter by more than one.

Methods

post

Releases the counter or increases the counter by more than one.

SyncCounter.post( [count] )
count The number of signals to be posted to this semaphore.

This method acts as release(), but it can be provided an optional parameter to give more than one thread the ability to acquire this structure.

It is not possible to use this method to reduce the internal count.

Made with http://www.falconpl.org