If a callback function can be called from multiple threads, then the callback must be thread-safe. Generally, callbacks are called from the thread that provoked the callback event, but some callbacks can be invoked by an internal Client-Library worker thread and execute in the context of the worker thread. Table 2-27 summarizes which thread invokes each callback type. Callbacks for use in a multithreaded environment should be coded according to the following rules:
Callbacks should follow the general implementation rules described in the “Callbacks” topics page.
Callback code must be thread-safe and follow the restrictions noted under “Write thread-safe code.”
Callbacks that can be invoked by a Client-Library worker thread require an appropriate design. The callback can run concurrently with mainline code, and access to any data structures shared between the callback and mainline code (including data stored as a CS_USERDATA property) must be thread-safe.