Semaphores

To keep tasks synchronised we use semaphores. These are global variables that are loaded with a unique value relating to the task that wishes to take control. This value is the Task's USER area address. A semaphore is initialised to zero. At this point any task may take control. When a task wishes a resource it ACQUIREs the semaphore. From now on no other task may acquire this resource as the semaphore is non zero. To allow others access the task it must RELINQUISH the resource and reset the semaphore. This mechanism provides for simple inter-task communication, provided the tasks do not hog any given resource. Tasks must co-operate.

If you refer to GLOBAL.F from our earlier demo, you will see (STREAM) is used as a semaphore for the 'pipe' <STREAM>. Each task acquires the pipe in turn to place it's ASCII string. As the pipe is shorter than the strings the semaphore is necessary to stop the strings getting intertwined. Only when (STREAM) is zero may a task ACQUIRE the pipe. From then on only that task may use the resource.

Contents