Pumpkin, Inc.

Pumpkin User Forums

Infinite loops

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

Infinite loops

Postby JOwsley » Fri Dec 06, 2002 3:10 am

The FAQ suggest an infinite loop is best for task programming. If I have a task which is 'single-shot', runs once then quits, should EXPLICITLY context switch with OS_Stop()?

e.g.

code:
MySingleTask()
{
for(;;)
{
OS_WaitBinSem(...);
if (OSTimedOut)
...
else
...
OS_Stop();
}
}

MySingleTask2()
{
OS_WaitBinSem(...);
if (OSTimedOut)
...
else
...
// should OS_Stop() be placed here?

}


So in the second example, can I assume the task is stopped, or is it technically still running? (implicit OS_Yield())

I am trying to save a few bytes here and there.

[This message has been edited by aek (edited December 06, 2002).]

Jake Owsley, PE
JOwsley
 
Posts: 4
Joined: Thu Dec 05, 2002 12:00 am
Location: Louisville, CO, USA

Re: Infinite loops

Postby aek » Fri Dec 06, 2002 4:51 am

quote:
So in the second example, can I assume the task is stopped, or is it technically still running? (implicit OS_Yield())
All Salvo services of the form "OS_" have in them an OS_Yield(). So, the OS_Yield() is implicit in OS_Stop(), and yes, you can simply terminate the task with an OS_Stop() and leave out the infinite loop.

In the Salvo user manual, the example for OS_Destroy() shows a "one-shot" task that does something similar to what you want ...

------------------

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

Re: Infinite loops

Postby aek » Fri Dec 06, 2002 4:54 am

One more thing (especially important with one-shot tasks) ...

If you forget to put a context-switch in a one-shot task, your code may very well appear to run properly. This can happen if another task is located immediately after the flawed one. What happens is that task execution "falls out of" the one-shot task and picks up again in the normal (infinite-loop) one ... it then context-switches using that context switcher and goes merrily along.

So remember, one of Salvo's Golden Rules is Every Task Must Have At Least One Context Switch.

------------------

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

cron