Difference between revisions of "Uno/Spec/Thread Affinity Bridge"
m (Restructured.) |
m |
||
Line 7: | Line 7: | ||
=== Feature === | === Feature === | ||
− | The Thread Affine Bridge protects [[../Thread Affine|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 | + | The Thread Affine Bridge protects [[../Thread Affine|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 may create an affinity to. |
− | + | The Affinity Bridge behaves as follows, | |
− | * | + | * entering a Thread Affine environment associates the current thread with it, in case the environment already has a thread associated, the enter blocks until no object is mapped anymore, |
− | * | + | * leaving a Thread Affine environment disassociates the current thread from the [[../Environment|Environment]], in case objects are still mapped, the leave blocks until no object is mapped anymore, |
− | + | * calling into the Thread Affine environment, leads to the invocation of the passed function by the associated thread, | |
− | * | + | * calling out of the Thread Affine environment, leads to the invocation of the passed function by the in-calling thread, in case of no in-calling thread, the associated thread calls out directly. |
− | * | + | |
=== Rationale === | === Rationale === |
Revision as of 15:11, 16 June 2006
version: 12568
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 may create an affinity to.
The Affinity Bridge behaves as follows,
- entering a Thread Affine environment associates the current thread with it, in case the environment already has a thread associated, the enter blocks until no object is mapped anymore,
- leaving a Thread Affine environment disassociates the current thread from the Environment, in case objects are still mapped, the leave blocks until no object is mapped anymore,
- calling into the Thread Affine environment, leads to the invocation of the passed function by the associated thread,
- calling out of the Thread Affine environment, leads to the invocation of the passed function by the in-calling thread, in case of no in-calling thread, the associated thread calls out directly.
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"
.