Uno/Spec/Thread Affinity Bridge
version: 12565
state: draft
type: specification
Thread Affinity Bridge
A Purpose Bridge protecting Thread Affine objects.
Feature
The Thread Affine Bridge protects Thread Affine objects from being called by wrong threads. It does this by providing a dedicated thread, into which it delegates the calls prior to invoking a particular object. This dedicated thread is therefor the thread objects create any affinity to.
API
enter: Associates the current thread with the Environmentleave: In case no objects are mapped it disassociates the current thread from the Environment, in case objects are mapped and this is the lastleave, it blocks until no object is mapped anymore.
callInto: Calls the desired method in the associated thread.callOut: Calls the desired method in the outer thread, if there is no outer thread yet, the associated thread is used.
Rationale
Some APIs have thread affinities in respect to particular handles they return. For example, on Win32 the window-destroy and -message functions require to be called by the same thread which actually created the window. This thread affinity is inherited when developing APIs on top of these thread affine APIs. In general, thread affine APIs are hard to program, especially in generic frameworks where it is not knowable before hand how long a thread lives and on whichs objects it calls.
API
A purpose bridge named "affine".