Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
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.


General Strategy

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:
  1. It can directly call suspend and resume
  2. It can change the priority of the other threads

The scheduler thread has a couple of ways for waking itself up:
  1. It can run at a high priority, and then have an infinite loop which sleeps using Delay's.
  2. 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.

Uses

Tweak and Croquet use a lower-priority scheduler to implement an asynchronous messaging model, by non-preemptively scheduling scripts.

Discussion

It would be great if someone can post some specific code for thread scheduling. -Lex Spoon, April 2005