![]() |
|
|
|
What is this thing?This is library of C functions that effectively implements a
reliable and portable lightweight multitasking environment for
the Palm Pilot OS. You can create threads, and coordinate the task
switching (co-operative task switching).
Although the Palm API has a multitasking API, it is not documented, supported, or sanctioned in any way. If you want multitasking, but don't want to 'break the rules' or fight to figure out the undocumented threading calls, then CoordTask is for you! How does it work?When a context switch occurs (task switch), the complete application task is copied aside. The other task's complete stack and register set is copied back, and execution magically carries on from the old thread! A more efficient implementation would create a new stack for each task and simply change the stack pointer, but the Pilot seems to have limited stack availability. By merely copying the old stack back onto the 'official' stack, I minimize the stack allocation and have a much more portable and stable solution (changing the stack pointer [a7] to dynamic memory may work, but I doubt it would be wise or sanctioned!). Is it safe?I chose the design I did to ensure a portable solution. Optimization was secondary. Since complete stack copying is happening at a context switch, you may find it slow with tons of threads and switches. It is completely possible that someone else may be able to improve the implementation. I originally got it working on Windows, so you'll notice some 'WIN32' stuff in the code. How do I use it?This code is designed to work ONLY with GNU CC, due to the inline assembly code in the C file CoordTask.c. Also, you have to be very careful with your compiler switches (see the makefile). If you port this to Metrowerks, please let me know! Can I use this code?You may freely distribute, use, or modify this code in any way. If you find bugs, make changes, or improve the code, please let me know! |