Synchronizing Multiple Tasks
Synchronizing the execution of multiple tasks by broadcasting to a semaphore is a commonly used technique. It may be important to have multiple tasks start executing at the same time. Obviously, on a single processor, only one task will actually execute at one time. However, the start of their execution will be synchronized to the same time. This is called a multiple task rendez-vous. However, some of the tasks synchronized might not be waiting for the semaphore when the broadcast is performed. It is fairly easy to resolve this problem by combining semaphores and event flags, as shown in the figure below For this to work properly, the task on the left needs to have a lower priority than the tasks waiting on the semaphore.
(1) Each task that needs to synchronize at the rendez-vous needs to set an event flag bit (and specify OS_OPT_POST_NO_SCHED
).
(2) The task needs to wait for the semaphore to be signaled.
(3) The task that will be broadcasting must wait for “all
” of the event flags corresponding to each task to be set.
(4) When all waiting tasks are ready, the task that will synchronize the waiting task issues a broadcast to the semaphore.