Re: Task API
- Posted by Michael Nelson <mikestar13 at sbcglobal.net> Sep 30, 2005
- 529 views
Robert Craig wrote: >I'm pretty sure I'm going to implement both of those (more or less). >I probably won't sort them by task id. You'll have to do that. >Would you like suspended tasks to be included in the list >of active tasks? Should task_active() distinguish between >suspended and normally-active tasks? Thanks Rob. IMO this will make the API pretty complete while still very simple. Sorting the list is not a priority. In both cases, suspended tasks should be considered inactive and retern false or be excluded from the list. My answer is not nessarily the correct one. Perhaps task_active should be instead task_status, returning an integer indicating active, suspended, or killed. Global task status constants could be provided for use as return values. Then task_all_active would become task_list(i) where the parameter might be a active, suspended, or killed. When the next release of the tasking interpreter comes out, I will develop a library to automate saving and restoring state during task switching. Basically, it would have a procedure task_link(i1,i2,i3) which would be passed the routine id's of three procedures: the save procedure, the restore procedure, and the termination procedure. The task lib would redefine task_yield to call the save procedures in the order they are defined, then do the task switch, then call the restore procedures in reverse order. A procedure would be provided (task_terminate) to initiate program termination and all of the terminate procedures would be called (the third id could be -1 if the particular library calling task_link does not need a termination procedure). The task lib would use crash_routine to invoke this automatically. Added functionality would be task_lock to prohibit task swiching during operations that need to be uninterrupted. Of course in your own code you will simply not call task_yield until you are finshed, but this provides for the case of calling a library routine which does call task_yield. A task_unlock procedure would be provided to release the lock and reenable task switching. The task which has the lock suspending or killing itself or returning from its task procedure would also release the lock. If you want to use any of these ideas in the interpreter or an official RDS lib, feel free. -- Mike