1. Use of Multi-Tasking feature
- Posted by cp Jul 11, 2011
- 1336 views
I have a program that will have two real-time tasks and one shared task. I need some clarification on how the procedures linked to the tasks need to be coded. The examples and docs indicate that for real-time tasks, the procedure needs a controlling loop (for or while) to make it run "forever" or x times.
procedure task_life() -- independent task: subtract life support energy while TRUE do if shuttle then p_energy(-3) else p_energy(-13) end if task_yield() end while end procedure
Is this required? Does this coding technique also apply to procedures that will be time shared. ie. If I have:
task_schedule(t1, 10)
Do I then code the procedure as:
procedure p_t1() integer i sequence sTemp for x = 1 to 10 do --some stuff end for task_yield() end procedure
Thanks in advance
2. Re: Use of Multi-Tasking feature
- Posted by mattlewis (admin) Jul 12, 2011
- 1271 views
I have a program that will have two real-time tasks and one shared task. I need some clarification on how the procedures linked to the tasks need to be coded. The examples and docs indicate that for real-time tasks, the procedure needs a controlling loop (for or while) to make it run "forever" or x times.
...snip...
Is this required? Does this coding technique also apply to procedures that will be time shared. ie. If I have:
The answer, of course, is: It depends!
It depends on how you want the task to work. If you want the task to continue running forever, then you need the while loop. When the task returns from its routine, the task ends, so if you want it to run again, you'll need to reschedule it.
So if it's a periodic thing that always has to happen, you probably want the while loop. If it's a one time thing that you just want to play nice with the rest of the system, you may need to yield occasionally, depending on how long it takes to finish, but then just let it return to end the task.
Matt