Index  |  Related pages  |  Classes  |  Functions  |  Entities  |  Function Sets  |  Groups

ClassSemaphore

class Semaphore( [initValue] )

Simple coroutine synchronization device. more...


Member list

Constructor
init Initializes the semaphore.
Methods
post Increments the count of the semaphore.
wait Waits on a semaphore.

Detailed description

The semaphore is a simple synchronization object that is used by coroutines to communicate each others about relevant changes in the status of the application.

Decrements the value of the semaphore, and eventually waits for the value to be > 0. When a Semaphore.wait method is called on a semaphore, two things may happen: if the value of the semaphore is greater than zero, the value is decremented and the coroutine can proceed. If it's zero, the coroutine is swapped out until the semaphore gets greater than zero again. When this happens, the coroutine decrements the value of the semaphore and proceeds. If a timeout parameter is given, in case the semaphore wasn't posted before the given timeout the function will return false.

The order by which coroutines are resumed is the same by which they asked to wait on a semaphore. In this sense, Semaphore.wait method is implemented as a fair wait routine.

The Semaphore.post method will raise the count of the semaphore by the given parameter (1 is the default if the parameter is not given). However, the calling coroutine won't necessarily be swapped out until a yield is called.


Class methods

init()

Initializes the semaphore.

Semaphore.init( [initValue] )
initValue

Initial value for the semaphore; if not given, 0 will be assumed.

By default, the semaphore is initialized to zero; this means that the first wait will block the waiting coroutine, unless a Semaphore.post is issued first.

post()

Increments the count of the semaphore.

Semaphore.post( [count] )
count

The amount by which the semaphore will be incremented (1 by default).

This method will increment the count of the semaphore by 1 or by a specified amount, allowing the same number of waiting coroutines to proceed.

However, the calling coroutine won't necessarily be swapped out until a yield is called.

wait()

Waits on a semaphore.

Semaphore.wait( [timeout] )
timeout

Optional maximum wait in seconds.

Decrements the value of the semaphore, and eventually waits for the value to be greater than zero.


Index  |  Related pages  |  Classes  |  Functions  |  Entities  |  Function Sets  |  Groups
Made with Faldoc 1.0.0