Difference between revisions of "Uno/Spec/Threading-Model"
From Apache OpenOffice Wiki
(Moved from udk.openoffice.org) |
(reworked:) |
||
| Line 2: | Line 2: | ||
version: {{REVISIONID}} <br> | version: {{REVISIONID}} <br> | ||
state: draft <br> | state: draft <br> | ||
| − | created: 12/12/ | + | created: 12/12/2005 <br> |
| − | changed: | + | changed: 03/06/2006 <br> |
type: specification <br> | type: specification <br> | ||
| Line 9: | Line 9: | ||
== UNO Threading Model == | == 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 | + | ;; : 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 |
| + | : '''Extended Environment Types:''' The different threading models are implemented as standard UNO environments (CPP: uno/environment.h). Environment specifications (e.g. "gcc3", "java") are extended by "purpose" specifiers (e.g. ":mutex", ":thread"). | ||
| − | : The | + | : The predefined purposes to objects according to their threading type are |
| − | : * | + | :* <code>":mutex" </code> - for thread unsafe code, |
| − | : * | + | :* <code>":thread"</code> - for thread affine code, and |
| + | :* <code>"" </code> - for thread safe code, to ensure compatibility with previous UNO versions. | ||
| − | : The | + | : '''Getting the Current Environment:''' The current purpose environment does not only vary with the implementation language (e.g. Java or G++), but also with the codes declared threading type. Therefor an API for accessing the ''current'' environment is provided. |
| − | : | + | ; Dependencies: None. |
| − | : | + | ; Compatibility Issues: None. |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Revision as of 15:38, 6 March 2006
author: Kr
version: 5807
state: draft
created: 12/12/2005
changed: 03/06/2006
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
- Extended Environment Types: The different threading models are implemented as standard UNO environments (CPP: uno/environment.h). Environment specifications (e.g. "gcc3", "java") are extended by "purpose" specifiers (e.g. ":mutex", ":thread").
- 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.
- Getting the Current Environment: The current purpose environment does not only vary with the implementation language (e.g. Java or G++), but also with the codes declared threading type. Therefor an API for accessing the current environment is provided.
- Dependencies
- None.
- Compatibility Issues
- None.