threadKey: parameter
The threadKey parameter enables you to coordinate threaded calls. All calls made using the same thread key run on the same thread. By default, VA Smalltalk uses the active process as the thread key so that all calls made from the same VA Smalltalk process run on the same operating system thread. You can also supply a nil thread key. Let's see how it works:
For Linux (UNIX):
Try the following script for UNIX systems:
| context |
context := CgDisplay default handle.
(PlatformFunctions at: 'XBell')
coroutineCallWith: context
with: 50
threadKey: nil.
The coroutineCallWith: works just like a callWith: when the threadKey is nil. The external function is executed on the main VA Smalltalk thread.
Let's try creating a thread and executing a couple of external functions on that thread.
For Linux (UNIX):
Use the following script for UNIX systems:
| context thread |
thread := 17. "Set thread to an arbitrary value"
context := CgDisplay default handle.
(PlatformFunctions at: 'XBell')
coroutineCallWith: context
with: 50
threadKey: thread.
(PlatformFunctions at: 'XBell')
coroutineCallWith: context
with: 50
threadKey: thread.
The first external function is executed under the new thread that was created. The second external function reuses that same thread. As a result, both external functions are executed under the separate thread associated with threadKey, and you are able to interact with other windows. For lengthy functions, be sure threadKey is not nil, otherwise users will not be able to interact with your application while the function is executing.
Last modified date: 05/14/2020