Page 1 of 1

multiple tasks waiting for same binsem

PostPosted: Sat Dec 15, 2007 11:08 am
by PresbyopticProgrammer
I understand that if multiple taks are waiting for the same binsem (or any particular event for that matter) that only one task will fire as a result of the binsem being signalled. But what if the binsem is subsequently signalled again (etc)? Do the remaining tasks waiting on it then fire? I would assume yes, as long as the initally fired task is not back in the waiting queue again (which is probably what my code error is at the moment, just realized, but want to make sure I get this).

Re: multiple tasks waiting for same binsem

PostPosted: Sat Dec 15, 2007 12:15 pm
by aek
Recall that Salvo dispatches tasks based on priority ...

If (as per your example):

* several tasks are waiting a single event
* the tasks have different priorities
* the event has not yet been signaled

then when the event is signaled (once), the highest-priority task will become eligible to run.

Now the question is what happens when the event is signaled again ... and the answer is that it will make the task with the highest priority that is (still) waiting on it eligible to run. Further signalings continue to follow this pattern.

So if the "second signaling" happens after the highest-priority task successfully waits the event and resumes waiting the event, then that same highest-priority task will be the task that is made eligible in the second signaling.

If, OTOH, that highest-priority task is doing something else (e.g. via OS_Delay()) when the event is signaled for the second time, then the highest-priority task is no longer waiting that event, and whatever highest-priority task is still waiting the event will be the one made eligible.

So you understand it correctly. If you want two or more tasks to "ping-pong" when the event is signaled, run them all at the same priority ...