Semaphore Functions

If several CTRL script threads run in parallel, it is impossible to predict how far a thread was processed at a specific time. The result of the parallel processing may not depend on the order of the instructions between the different threads. Sometimes an application, however, requires a certain order. For example when threads must be protected against simultaneous access to a shared resource or when a thread should only be processed after a specific condition is fulfilled. Synchronization describes the restriction of the free parallel processing.

A non-computing example of a semaphore would be dining at a restaurant. A semaphore is initialized with the number of chairs in the restaurant. As people arrive, they want a seat. As seats are filled, semAvailable() is decremented. As people leave, the semAvailable() is incremented, allowing more people to enter. If a party of 10 people want to be seated, but there are only 9 seats, those 10 people will wait, but a party of 4 people would be seated (taking the available seats to 5, making the party of 10 people wait longer).

In CTRL the following semaphore functions are available:

semAcquire(),

semAvailable(),

semRelease()