links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Squeak Threading Model
Last updated at 9:04 pm UTC on 31 May 2007
A Squeak thread is implemented with class Process. This page uses the word "thread" in order to remain accessible to new Squeak users.

The Squeak scheduler is cooperative between threads of the same priority, and preemptive between threads of different priorities. A thread can be interrupted by threads of a higher priority, but it will (sort of) never be interrupted by a thread of the same priority, and it will never be interrupted by a thread of a lower priority. The "sort of" is because whenever a thread is interrupted by a higher-priority thread, it moves to the back of its run queue. See True Cooperative Threads?.

Alternative thread schedulers can be implemented within Squeak, by having a high priority thread act as a schedular. The general strategy is for a high priority thread to periodically come to life and either juggle the run queues or juggle thread priorities. See Alternative Thread Schedulers.

Squeak threads are implemented on top of a single OS thread. This is sometimes called a "green threads" architecture. The main disadvantage to this approach is that it is impossible to use multiple CPUs even when the machine has them available. This leads some to call for Using Multiple OS Threads. Using multiple OS threads has its own problems, however. A major implementation challenge is Multi-threaded Garbage Collection, and additionally there are general application-level challenges caused by Preemptive Threads with Shared Memory.

Regarding performance, green threads perform faster than OS threads due to avoiding context switches. For multiple CPUs the picture is less clear.

Some software architectures require preemptive threads. For example, Thread per HTTP Request. In general, preemptive threads are needed to support Preemptive Threads with Shared Memory. An alternative is the Event-Loop Architecture. There is disagreement on which architecture is better; see the pages for details.

See Also

Process Browser for how to view the currenttly running threads
Process and How do you do something every so often? for relationship between delay and threads.
A Decent ObjectC Bridge for relationship between external processes and threads.
Garbage Collection and Semaphore for an example of a process blocking on a semaphore.
OSProcess for how to gain access to operating system processes.
Squeak Threading Model for a discussion on switching to Mesa-monitors as a synchronization construct.
Squeak's threading architecture -- why can't Squeak do SMP yet
Single-threaded Code Loading
Thread-safe More on what's tread safe and whats not and why
Multi-Threaded Squeak - a page by John Olson about using threads in Squeak
http://www.laputan.org/brant/brant.html Brandt on wrappers
Thinking about massively parallel Smalltalk