Using threads
To see how threads work, you can use the functions that are already registered in the PlatformFunctions dictionary. Then, choose the coroutineCallWith: message that takes the number of arguments that your external function needs.
Let's try a couple of examples, with and without using threads. The scripts you need to write will vary by platform.
For Windows:
To cause a beep to sound on Windows with the frequency of 440 hertz and a duration of 3 seconds, evaluate the following script from the System Transcript:
(PlatformFunctions at: 'Beep')
callWith: 440 with: 3000.
For Linux (UNIX):
To cause a beep to sound on UNIX systems, evaluate the following script from the System Transcript:
| context |
context := CgDisplay default handle.
(PlatformFunctions at: 'XBell')
callWith: context with: 50.
The callWith: message runs the beep process on the main VA Smalltalk thread, causing all other processing to stop until the beep function is complete. Notice that while this example is running, if you move your mouse pointer outside the System Transcript, it remains a busy pointer, and you cannot interact with other windows.
To run the beep function on another thread, and free the main VA Smalltalk thread to continue processing, use the coroutineCallWith:with: message.
For Linux (UNIX):
For UNIX systems, execute the following script from the System Transcript:
| context |
context := CgDisplay default handle.
(PlatformFunctions at: 'XBell')
coroutineCallWith: context with: 50.
Notice that while this example is running, you can move your mouse pointer outside the System Transcript and interact with other windows.
Last modified date: 05/14/2020