Re: Multitasking Preview Release
- Posted by Robert Craig <rds at RapidEuphoria.com> Sep 21, 2005
- 594 views
Jonas Temple wrote: > Will this handle the following (in Windows): > > * Routine "a" is executed when a user clicks a button > * "a" starts task "b" > * task "b" calls a routine in a .DLL that extracts information from another > computer. > Sometimes the answer comes back quickly and sometimes the answer comes back > in minutes > (i.e. SQL query). For this example, let's say 5 minutes. > * user can't wait for answer and wants to cancel the query. I add a button to > the > window that lets the user cancel the query. User clicks button and I use > task_kill() > against task "b". > > Since task "b" is still waiting for the routine in the DLL to return, would > taks "b" > be cancelled immediately or when the DLL returns control to task "b"? With cooperative multitasking, task b can't call a routine in a .dll and then wait inside that call, without holding up all the other tasks. What you need is some kind of asynchronous (non-blocking) I/O call, that will let task b return from the call immediately, and then check periodically to see if the I/O is complete. You could set up task b to check, say, every 2 or 3 seconds to see if the I/O is complete. While it's doing that, other tasks could handle the user interface, and any other processing that you want to do in parallel with task b. If the user wants to stop the I/O, you could let task b know via a global variable that it should quit, or you could call task_kill() on task b to force it to stop the periodic checking. In general, when task A kills task B using task_kill(), task B will be stopped on a task_yield() statement. Task B will not run again, and it's call stack and private variables will be freed up. If task A kills itself by calling task_kill(task_self()), task A will actually continue until it hits a task_yield() statement, then it's game over for task A. Tasks also die if/when their procedure returns. Something that's not clear from the docs (I'll fix it), is that each program has an initial task that's created automatically. It can be scheduled like the other tasks that you explicitly create. Its task id is 0. Until the initial task yields, no other task can run. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com