LSWVST Support for OS-Threads and Fibers

The green-thread limitations

Traditionally Smalltalk is single threaded. It supports green threads, which means multithreading is simulated in one OS-thread. The class which hosts a Smalltalk-thread is Process. Also a limited support for OS-threads is called the Non-Blocking API. A Smalltalk program can call-out to native code in a separate thread. This works fine in most cases. But if Smalltalk is called back by the OS the associated Smalltalk process cannot be put in a wait state becasue the OS-Callback need to return. In a development system one needs to suspend a green thread for debugging purposes . Here Smalltalks like VSE use a workaround to enable debugging of one group of recursive callbacks like wm_create which  are send by the OS to control a Window before it is opened. VSE queues wm_create callbacks in whenValid Dictionary and executes them after the Window is created. This nice trick works only for certain callbacks. If you put a halt in wmCreate: you will just get a non-debuggable stack-trace. In short for debugging purposes you need OS-Threads. The hack in VSE creates the problem that true development of nice User-Interfaces is very difficult in VSE. VSE was sufficient for the early state of Windows in the beginning of the 90ies.

There are further problems if only green threads are supported. For instance If you want to change properties of a running animation by gauges ike scrollbars you have to introduce polling mechansimns to get the OS-Messages processed. While this is not so difficult for one window it gets worse if you have more than one animated window - you have to repeat the time-slicing mechanisms of the underlying OS.

Also today more and more multiprocessor-systems are in use. Smalltalk cannot take advantage of more than one processor if only green-threads are supported. 

Here you need true OS-thread support. But in a garbage collected language that is not so easy. A solution is to separate garbage collection in an own thread. This solution is used by languages like Java and C#. But multithreaded garbage collection is much more complicated and less efficient than its single threaded counterpart.

LSWVST supports all kinds of threads

To lift the secret what kind of multithreading does LSWVST support:

To create a new Thread simply execute

    ( thread := SmalltalkThread new ) launch.