|
|
| Author |
Message |
DH* Guest
|
|
Posted: 19 July 2006, 18:19 PM Post subject: Multi-tasking question |
|
|
| Assuming one main task and one secondary task, my understanding is that each task will get control at each RTC Tick which means each task gets about a 2mS time slice. My secondary task only needs about 1mS each time it is activated (by WaitForInterrupt). Instead of idling until the next RTC Tick, is there a way to return to the main task earlier without killing the secondary task? |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR
|
|
Posted: 19 July 2006, 18:45 PM Post subject: |
|
|
| Quote: | | [...] is there a way to return to the main task earlier without killing the secondary task? |
A call to Delay(0.0) will allow a task switch. Whether a task switch actually occurs depends on whether another task is ready/able to run.
As currently implemented, the next task to run will execute, at most, the remainder of the time slice unless, of course, it locks itself, etc. It might be better if the subsequently executing task got the remainder of the current time slice plus another whole time slice. The implemented behavior is the same as that of BasicX. |
|
| Back to top |
|
 |
DH* Guest
|
|
Posted: 19 July 2006, 18:52 PM Post subject: |
|
|
| dkinzer wrote: | | It might be better if the subsequently executing task got the remainder of the current time slice plus another whole time slice. | That would be better. |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR
|
|
Posted: 19 July 2006, 19:42 PM Post subject: |
|
|
I neglected to mention in my earlier reply that you can switch to a specific task using RunTask(). The desired task is indicated by passing its task control block array. For the Main() task, this is slightly more difficult because its task control block is not explictly defined. Rather, its task control block is located at the beginning of the remaining, unallocated RAM. The address of Main() task's task control block is available as Register.TaskMain. The CByteArray() conversion function needs to be used in conjunction with this in order to pass it to RunTask().
| Code: | | Call RunTask(CByteArray(Register.TaskMain)) |
Alternately, and more succinctly, you can switch to the Main() task by simply omitting the parameter:
Last edited by dkinzer on 20 July 2006, 0:50 AM; edited 1 time in total |
|
| Back to top |
|
 |
DH* Guest
|
|
Posted: 19 July 2006, 21:34 PM Post subject: |
|
|
| That helps code readability. |
|
| Back to top |
|
 |
|