Alternative Thread Schedulers
Last updated at 12:14 pm UTC on 23 September 2005
Squeak has a built-in thread scheduler. However, th threading model is flexible enough to implement alternative schedulers should a user desire.
The general strategy for implementing an alternative scheduler is to fork a high-priority thread (see Process) and then have that thread act as the scheduler.
The scheduler thread then has several options for scheduling the other threads:
- It can directly call suspend and resume
- It can change the priority of the other threads
The scheduler thread has a couple of ways for waking itself up:
- It can run at a high priority, and then have an infinite loop which sleeps using Delay's.
- The main scheduler thread can run at a low priority, so that it immediately wakes up whenever all of the scheduled threads have become inactive. This approach could be coupled with a high-priority thread which uses method #1 in order to forcibly wake up the scheduler thread every once in a while even if the scheduled threads try to hog the CPU.
Tweak and Croquet use a lower-priority scheduler to implement an asynchronous messaging model, by non-preemptively scheduling scripts.
It would be great if someone can post some specific code for thread scheduling. -Lex Spoon, April 2005