Uno/Article/Multi-Thread Programming

From Apache OpenOffice Wiki
< Uno
Revision as of 14:32, 31 May 2006 by Kr (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Multi Threading Programming

UNO is inherently multi threaded. Every instance of a UNO components may be accessed by multiple threads concurrently. The UNO threading framework provides support to simplify multi thread programming.

Note: The UNO runtime provides APIs for implementing any whished scenario. Including objects shared between different purpose environments or the instantiation of a Thread Safe component in a Thread Unsafe environment. These mechanisms a in place to implement the Threading Framework itself, and to allow the programmer to gain full control, if needed.

Components

If you are going to implement a UNO component, you need decide on the threading architecture of your particular component. You basically have three choices:

  • Thread Unsafe
  • Thread Safe
  • Thread Affine

In most cases, the choice should be Thread Unsafe, actually leaving proper synchronization of method calls to the system. There are only rare cases where you want to implement your component Thread Safe. Either

  • your component should or must allow the concurrent execution of some methods, or
  • your component wants to avoid the overhead associated with leaving synchronization to the system.

One case, where your components must allow the concurrent execution of methods is, when you want to abort it. UNO currently does not offer a mechanism to do this generically, so that particular objects must provide dedicated methods for abortion. An example for this is the com.sun.star.impl.Acceptor implementation.

The overhead for automatic synchronization only affects inter-environment calls. In most cases, the threading architecture should be designed in a way, that closely connected objects happen to exist in the same environment. Basically ensuring a low call frequency, converting the advantage of self synchronized methods to the reverse.

Note: It is planned, to support the selection of an Implementation Environment by a macro or an include. Some experiments have been done, so no final decisions has been made yet.

Libraries

Libraries providing functions dealing with UNO references may be implemented as

  • free, meaning that the library can deal with any kind of reference, or as
  • specialized, meaning that the library can deal with one particular type of references only.

Certainly, functions of the domains can mixed, depending on the libraries purpose, this may or may not be good style.

Note: Unfortunately, no type safe specialized purpose references are yet available for any UNO language binding. So, this is planned. Currently, the only possible way to detect the purpose of a reference is at runtime, via the getCurrentEnvironment runtime function.

The cppuhelper library dynamically checks the current environment, and returns matching references, e.g guaranteeing that Thread Safe and Thread Unsafe objects do not get mixed.


Applications

Personal tools