User's Guide

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, VisualAge uses the active process as the thread key so that all calls made from the same VisualAge process run on the same operating system thread. You can also supply a nil thread key. Let's see how it works:

OS/2 icon
Try the following script for OS/2:
(PlatformFunctions at: 'DosBeep')
    coroutineCallWith: 440
    with: 3000
    threadKey: nil.

UNIX icon
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 VisualAge thread.

Let's try creating a thread and executing a couple of external functions on that thread.

OS/2 icon
Use the following script for OS/2:
| thread |
thread := [] fork.        "Create a new suspended thread"
(PlatformFunctions at: 'DosBeep')
    coroutineCallWith: 440
    with: 3000
    threadKey: thread.
(PlatformFunctions at: 'DosBeep')
    coroutineCallWith: 999
    with: 3000
    threadKey: thread.

UNIX icon
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.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]