Training
×

Semaphore: Mutual Exclusion

A semaphore can be used for mutual exclusion; e.g., when a double linked list is maintained, every element in the list has both a forward and a backward link. Inserting a new element in the chain requires updating more than one link and once the updating has been started, the chain is in a bad state until all updating has been completed. To avoid accesses in such a state, all users of the list agree to wait for the semaphore unit before using the list, and to release the unit again after the list access is complete.
Note that INtime does not know the relation between the list and the semaphore, so if a thread accesses the list without waiting for the semaphore unit, this will not be recognized as a fault.