Multithreading

How to:

Enable Context-Safety for Multithreaded Programs

Reference:

Thread-Safe API Considerations

Thread-safe API support allows a multithreaded program to create separate but complete environments, each having the ability to specify its own configuration and defaults. All program activities are based within the context created by each thread and do not interfere with any other context, to the extent permitted by the physical protocol layers. Some physical protocols share resources, and thus are not appropriate for multiple context use.

The API can operate in two modes:

The two modes can be mingled. This allows multiple threads to operate simultaneously within each created context.

Multiple context programming requires no special techniques by the application if only a single SCB is used for each context. Multiple-thread programming requires that you instruct the API to manage threads.

Since a multithreading environment may not be able to maintain addressability through server callbacks, the EDASET variable - EDA_VAR_USERAREA (158) - enables an application to store a value into the EDA_ID. This value can be retrieved during the callback using EDAINSPECT. It helps to assign a pointer to your own context information here, making this data available to callback routines. The callback block contains the EDA_ID for which the callback is being made.


Top of page

Procedure: How to Enable Context-Safety for Multithreaded Programs

To enable the thread-safe API, issue an EDASET call for the variable EDA_VAR_AUTOLOCK (305) immediately following the EDAINIT in the EDAPINIT call. This setting is not required when issuing multiple EIDs that have only a single SCB each.

Setting AUTOLOCK causes the API to apply appropriate locking during its operation. This allows users to intermingle operations on a single EDA_ID over several threads, but it adds the benefit of lock management.


Top of page

Reference: Thread-Safe API Considerations

The following limitations apply:


iWay Software