Pumpkin, Inc.

Pumpkin User Forums

multiple tasks waiting for same binsem

If you can't make Salvo do what you want it to do, post it here.

multiple tasks waiting for same binsem

Postby PresbyopticProgrammer » Sat Dec 15, 2007 11:08 am

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).
Posts: 14
Joined: Wed Nov 21, 2007 12:00 am
Location: Fort Valley, VA, USA

Re: multiple tasks waiting for same binsem

Postby aek » Sat Dec 15, 2007 12:15 pm

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 ...


Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Return to Coding

Who is online

Users browsing this forum: No registered users and 1 guest