Smalltalk allows multiple lightweight processes (also called threads or tasks) to execute pseudo concurrently. These run within the same address space (in one heavy weight Unix process) and can communicate via shared objects. Process scheduling is priority driven, where scheduling is implemented fully in smalltalk (i.e. all algorithms are open and can be changed if there is a need to do so).
Each process has its own automatically growing stack which is protected against overflow. No stack size definition is needed at process creation time - the system will allocate additional stack memory in reasonable small increments. Stack overflow can be cought (see exceptions) and handled gracefully (it is even possible to restart or continue with more stack space after such an exception).
Also, multiple processes can be debugged simulatiously (using the symbolic Debugger) - even while executing concurrently.
The windowing interface makes use of processes, by executing each view in a separate process. This means, that other views are not locked up by one view being debugged or busy (which is the case in pure event driven systems).
The interresting classes are:
Process
represents a thread of control in smalltalk.
An arbitrary number (limited by memory) of processes can execute concurrently
within a smalltalk system.
These processes (also called threads or lightweight processes)
are not implemented as Unix processes,
but instead are created, managed and scheduled by smalltalk itself.
They all run in the same address space; therefore, the same objects can be accessed by different processes.
aBlock fork
aBlock forkAt:priority
aBlock newProcess
aProcess priority
aProcess state
aProcess id
aProcess name
aProcess priority:newPriority
aProcess suspend
aProcess resume
aProcess terminate
ProcessorSchedulers
sole instance (named Processor
)
is responsible for scheduling among running processes. In contrast to other
smalltalk implementations, scheduling is done at the smalltalk language level.
This allows for different schedulers to be implemented if required.
Processor
:
Processor activeProcess
Processor activePriority
Processor userSchedulingPriority
Processor userBackgroundPriority
Processor terminateActive
Processor yield
Processor suspend:aProcess
Processor resume:aProcess
Semaphore new
Semaphore forMutualExclusion
aSemaphore wait
aSemaphore signal
aSemaphore critical:[ ... criticalBlock ...]
Processor signal:aSemaphore onInput:fileDescriptor
Processor signal:aSemaphore onOutput:fileDescriptor
Processor signal:aSemaphore afterSeconds:numberOfSeconds
Delay
and ExternalStream
for portability.
Delay
wraps the above timer based suspend into a portable interface.
(Delay forSeconds:numberOfSeconds) wait
(Delay forMilliseconds:numberOfSeconds) wait
Copyright © Claus Gittinger Development & Consulting, all rights reserved
(cg@ssw.de)