Threading Considerations

When using the RexxCreateInterpreter() API to create a new interpreter instance, a RexxThreadContext pointer is returned with the interpreter instance. The thread context vector allows you to perform operations such as running Rexx programs while in the same thread context as the RexxCreateInterpreter() call.

A given interpreter instance can process calls from multiple threads, but a RexxThreadContext instance must be obtained for each additional thread you wish to use. A new thread context is obtained by calling AttachThread() using the RexxInstance API vector returned from RexxCreateInterpreter(). Once a valid RexxThreadContext interface has been created for the thread, any of the operations defined for a thread context are usable on that thread. Before the thread terminates, the DetachThread() API must be called to remove the attached thread from the interpreter instance.

The interpreter is capable of asynchronous calls to interpreter APIs from signal or event handlers. When called in this manner, it is possible that AttachThread will be called while running on a thread that is already attached to the interpreter instance. When a nested AttachThread() call is made, the previous thread context is suspended and the newly created thread context is now the active one for the source thread. It is very important that DetachThread() be called to restore the original thread context before you return from the signal handler.