Uno/Spec/Threading-Model

From Apache OpenOffice Wiki
< Uno‎ | Spec
Revision as of 16:06, 13 April 2006 by Kr (Talk | contribs)

Jump to: navigation, search

author: Kr
version: 7869
state: draft
created: 12/12/2005
type: specification


UNO Threading Model

Feature
A UNO Runtime provides support for implementing thread safe, thread unsafe or thread affine code.
The UNO Threading Model allows code to leverage external locking, respectively to leverage thread specificy. Code can either be specified to be
  • thread safe, or to be
  • thread unsafe, or to be
  • thread affine.
 
Thread Safe Code
Thread safe code takes care of all threading issues, including locking critical sections etc. Code doing blocking I/O needs to be thread safe, so that system calls can be interrupted. Thread safe code may also be used to allow high concurrency, while avoiding the runtime overhead of external locking.
 
Thread Unsafe Code
Thread unsafe code must not care of any threading issues, except thread affinity. Thread unsafe code must be implemented Thread Transparent. On the desgined level of granularity methods are guaranteed to not be called concurrently. The calling thread may vary over time.
The Unsafe Threading Model should become the standard model of implementation. Ensuring all code to be in this Model and utilizing only one thread should give optimal performance without any threading overhead.
 
The Thread Affine Code
Thread affine code must not care of any threading issues, including thread affinity. Thread affine code must be implemented Thread Transparent. On the designed level of granularity methods are guaranteed to not be called concurrelty. Thread calling thread does not vary over time.
Declaring code to be thread affine is e.g. very usable for programming Windows thread affine APIs as OLE or WIN32.


Rationale
API
Purpose UNO Environments: The different threading models are accessible as standard UNO environments (CPP: uno/environment.h). Environment specifications (e.g. "gcc3", "java") are extended by "purpose" specifiers (e.g. ":mutex", ":thread"), purpose specifiers may be chained (e.g. ":mutex:debug:test").
The predefined purposes to objects according to their threading type are
  • ":mutex" - for thread unsafe code,
  • ":thread" - for thread affine code, and
  • "" - for thread safe code, to ensure compatibility with previous UNO versions.
Stacked Environments: The current (purpose) environment does not only vary with the implementation language (e.g. Java or C++), but also with the executed codes declared threading type. Therefor an API for accessing the current environment is provided.
Cascaded Mappings: Purpose environments may be passed to the Runtime for getting cascaded mappings ("gcc3" => "java:mutex:debug").
Implementation Environments: Client code as well as service code may be declared once, to either be thread safe, thread affine or thread unsafe.
Dependencies
Thread Environment
Mutex Environment
Cascaded Mapping
Compatibility Issues
None.
Personal tools