Difference between revisions of "Effort/Make VCL Thread-Transparent"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Short MutEx Acquiration Times)
 
(34 intermediate revisions by the same user not shown)
Line 1: Line 1:
[mailto:Kay.Ramme@sun.com], [mailto:Kai.Sommerfeld@sun.com]
+
Type: [[Uno/Term/Effort|Effort]]  State: 85%  Owner: [[KR|Kay Ramme]]
  
Status: in progress
+
[[VCL]] (Visual Components Library) provides the OOo base widget set and windowing abstraction. It manages the event loop and dispatches the events. It also owns the display connection and manages various resources, e.g. fonts.
  
== Making VCL Thread Transparent ==
+
The goal of this effort is, to make VCL [[Uno/Term/Thread Transparent|thread-transparent]].
VCL provides the OOo base widget set and windowing abstraction. It manages the event loop and dispatches the events. It also owns the display connection and manages various resources, e.g. fonts.
+
  
=== VCL hampers [[Uno/Term/Thread Transparent|Thread Transparency]] ===
+
==Problem==
VCL hampers [[Uno/Term/Thread Transparent|Thread Transparency]] in the following ways:
+
===[[VCL]] hampers [[Uno/Term/Thread Transparent|Thread-Transparency]]===
* VCL is [[Uno/Term/Thread Affine | Thread Affine]] under Windows - bascially letting shine through the Win32 thread affinity regarding window messages, window construction and window destruction.
+
[[VCL]] hampers [[Uno/Term/Thread Transparent|thread-transparency]] in the following ways:
* VCL provides the Solar MutEx, which needs to be acquired befor VCL can be called.  
+
* On Win32:
* VCL completely releases the Solar MutEx in some sitations, without any hints at the API.
+
** [[VCL]] is [[Uno/Term/Thread Affine|thread-affine]] under Windows - basically letting shine through the Win32 [[Uno/Term/Thread Affine|thread-affinity]] regarding window messages, window construction and window destruction.
 +
** [[VCL]] provides access to the main-thread, which basically is the thread which initializes [[VCL]] and which is expected to eventually enter the event-loop, on Win32.
 +
** [[VCL]] initializes the initiating threads apartment as STA on Win32. See {{Uno/UDKlink|vcl/source/app/svmain.cxx|gsl}}
 +
* [[VCL]] provides the [[Terms/Solar Mutex|Solar Mutex]], which needs to be acquired before [[VCL]] can be called.  
 +
* [[VCL]] completely releases the [[Terms/Solar Mutex|Solar Mutex]] in some situations, without any hints at the API.
  
VCLs internals are not protected against concurrent access, except by the Solar MutEx, which needs to be locked from the outside. VCLs API only provides blocking or polling functions for accessing the event loop, which is especially bad as it does not offer a way, to avoid long acquired MutExes, while waiting for events, except by actively polling.
+
[[VCL]]s internals are not protected against concurrent access, except by the [[Terms/Solar Mutex|Solar Mutex]], which needs to be locked from the outside. [[VCL]]s API only provides blocking or polling functions for accessing the event loop, which is especially bad as it does not offer a way, to avoid long acquired MutExes, while waiting for events, except by actively polling.
  
=== Make VCL Thread Transparent ===
+
==Solution==
To make VCL thread transparent, we plan to
+
===Make VCL [[Uno/Term/Thread Transparent|Thread-Transparent]]===
* remove the Solar MutEx completely and to declare VCL to be [[Uno/Term/Thread Unsafe | Thread Unsafe]], therefor going to run in the <code>"c++:unsafe"</code> [[Uno/Spec/Purpose Environment|UNO Purpose Environment]], and to  
+
To make VCL [[Uno/Term/Thread Transparent|thread-transparent]], we plan to
* encapsulate calls to the [[Uno/Spec/Thread Affine | Thread Affine]] Win32 API, in a way, that this thread affinity is not visible from the outside ([[Uno/Term/Thread Transparent|Thread Transparency]]). The goal being that VCL behaves as an ordinary library, not showing any threading behavior at all.
+
* remove the [[Terms/Solar Mutex|Solar Mutex]] completely and to declare [[VCL]] to be [[Uno/Term/Thread Unsafe|thread-unsafe]], therefor going to run in the <code>"c++:unsafe"</code> [[Uno/Spec/Purpose Environment|Uno Purpose Environment]], and to  
 +
* encapsulate calls to the [[Uno/Term/Thread Affine|thread-affine]] Win32 API, in a way, that this [[Uno/Term/Thread Affine|thread-affinity]] is not visible from the outside ([[Uno/Term/Thread Transparent|thread-transparency]]). The goal being that [[VCL]] behaves as an ordinary library, not showing any threading behavior at all.
  
=== Short MutEx Acquiration Times ===
+
===Support short MutEx Acquisition Times===
To ensure short MutEx acquiration times, we plan to
+
To ensure short MutEx acquisition times, we plan to
* add a system handle providing API, so that we can poll/select on the handle in an outer loop, and only need to enter VCL in case of pending events. Unfortunately, this seems to depend on the removal of the internal VCL event loop, so we may go with an interims solution.
+
* add a system handle providing API, so that we can poll/select on the handle in an outer loop, and only need to enter [[VCL]] in case of pending events. Unfortunately, this seems to depend on the removal of the internal [[VCL]] event loop, so we may go with an interim solution.
  
=== Side Effets ===
+
===Fix Side Effects===
* Some Win32 based OOo components (e.g. DDE) rely on their initializing thread to eventually enter the VCL event loop, to dispatch messages for objects created during this initialization. These implementations need to be adapted, to either delegate Win32 thread affine calls into VCLs new internal thread, or to create a thread for dispatching purposes by their own.
+
* Some Win32 based OOo components (e.g. DDE) rely on their initializing thread to eventually enter the [[VCL]] event loop, to dispatch messages for objects created during this initialization. These implementations need to be adapted, to either delegate Win32 [[Uno/Term/Thread Affine|thread-affine]] calls into [[VCL]]s new internal thread, or to create a thread for dispatching purposes by their own.
* With the removal of the Solar MutEx, VCL can not release a protecting MutEx anymore, which it currently does when <code>executing</code> a dialog. That means, that a protecting MutEx will stay acquired during presence of the dialog, basically disallowing other threads to enter VCL. This is should be addressed by [[Async Dialogs | making the office dialogs asynchron]] and deprecating / removing the <code>execute</code> method.
+
* With the removal of the [[Terms/Solar Mutex|Solar Mutex]], [[VCL]] can not release a protecting MutEx anymore, which it currently does when <code>executing</code> a dialog. That means, that a protecting MutEx will stay acquired during presence of the dialog, basically disallowing other threads to enter [[VCL]]. This is going to be be addressed by [[Effort/Make Dialogs Asynchronous|making the office dialogs asynchronous]] and deprecating / removing the <code>execute</code> method.
  
=== Time Frame ===
+
==Time Frame==
At least [[Removing the Solar MutEx]] and [[Encapsulating the inherited Win32 Thread Affinity]] are going to depend on [[Uno/Effort/Creating the Uno Threading Framework]], therefor VCL Thread Transparency will earliest be available after the UTF.
+
At least the [[Effort/Encapsulate the Win32 thread affinity]] depends on [[Uno/Effort/Binary/Extend Threading-Model]], therefor [[VCL]] thread-transparency will earliest be available after the {{Uno/CWS|SRC680|bunoexttm}} [[CWS]].
  
; Dependencies
+
==Tasks&CWS==
:{|border="1" cellspacing="0" class="wikitable"
+
{|border="1" cellspacing="0" class="wikitable"
 
|- style="background:#efefef;"  
 
|- style="background:#efefef;"  
| Effort || State
+
| Title || State || [[CWS]] || Dependencies
 
|-
 
|-
| [[Async Dialogs | Make Dialogs Asynchronous]] || in progress
+
| [[Effort/Make Dialogs Asynchronous]] || style="background:yellow;" | 75% || {{Uno/CWS|SRC680|asyncdialogs}} {{Uno/CWS|SRC680|asyncdialogs2}} ||
 
|-
 
|-
| [[Encapsulate the inherited Win32 Thread Affinity]] || UTF2
+
| || || ||
 
|-
 
|-
| [[Fix WIN32 DDE support (see above)]] || open
+
| Move [[Terms/Solar Mutex|Solar Mutex]] implementations (SalYieldMutex) into platform independent part. || style="background:lightblue;" | 0% || {{Uno/CWS|SRC680|vclYieldmutexReduction}}  ||
 
|-
 
|-
| [[Remove the Solar MutEx]] || proof
+
| Win32: Remove unnecessary "SendMessage" indirections in VCL backend. || style="background:lightblue;" | 0% || {{Uno/CWS|SRC680|vclYieldmutexReduction}} ||  
 
|-
 
|-
| [[Create a Handle API]] || open
+
| || || ||
 
|-
 
|-
 +
| Avoid releasing the [[Terms/Solar Mutex|Solar Mutex]] while being Application::Execute / Dialog::Execute || style="background:yellow;" | 75% || {{Uno/CWS|SRC680|vclThreadTransparency}} || {{Uno/CWS|SRC680|asyncdialogs2}}
 +
|-
 +
| Win32: [[Effort/Encapsulate the Win32 thread affinity|Encapsulate thread-affinity.]] || style="background:yellow;" | 75% || {{Uno/CWS|SRC680|vclThreadTransparency}} || {{Uno/CWS|SRC680|bunoexttm}}
 +
|-
 +
| Fix "main-thread" API usages. These are thread-affinity workarounds only. || style="background:lightblue;" | open || {{Uno/CWS|SRC680|vclThreadTransparency}} ||
 +
|-
 +
| Win32: Fix (potential) implicit "GetMessage" dependencies. || style="background:lightblue;" | open || {{Uno/CWS|SRC680|vclThreadTransparency}} || {{Uno/CWS|SRC680|bunoexttm}}
 +
|-
 +
| Remove "main-thread-executor". || style="background:lightblue;" | open || {{Uno/CWS|SRC680|vclThreadTransparency}} ||
 +
|-
 +
| Remove "main-thread" access API (vcl/inc/svapp.hxx). || style="background:lightblue;" | open || {{Uno/CWS|SRC680|vclThreadTransparency}} ||
 +
|-
 +
| Create handle API. || style="background:yellow;" | 75% || {{Uno/CWS|SRC680|vclThreadTransparency}} || {{Uno/CWS|SRC680|bunoexttm}}
 +
|-
 +
| Deprecate Application::Execute and Dialog::Execute. || style="background:yellow;" | 75% || {{Uno/CWS|SRC680|vclThreadTransparency}} ||
 +
|-
 +
| Adapt soffice event-loop (desktop/source/app) to the handle API. || style="background:yellow;" | 75% || {{Uno/CWS|SRC680|vclThreadTransparency}} ||
 +
|-
 +
| || || ||
 +
|-
 +
| Win32: Simplify Drag&Drop and Clipboard by using [[Uno/Binary|Binary Unos]] extended threading model || style="background:lightblue;" | open || {{Uno/CWS|SRC680|vclSingleDispatch}} || {{Uno/CWS|SRC680|vclThreadTransparency}}
 +
|-
 +
| || || ||
 +
|-
 +
| Remove [[Terms/Solar Mutex|Solar Mutex]] usages. || style="background:lightblue;" | open || {{Uno/CWS|SRC680|vclRetireSolarMutex}} || {{Uno/CWS|SRC680|vclThreadTransparency}} {{Uno/CWS|SRC680|NewThreadingArch}}
 +
|-
 +
| Remove [[Terms/Solar Mutex|Solar Mutex]] (AKA YieldMutex) API and implementation. || style="background:lightblue;" | open || {{Uno/CWS|SRC680|vclRetireSolarMutex}} ||
 
|}
 
|}
  
  
 
[[Category:Effort]]
 
[[Category:Effort]]
 +
[[Category:VCL]]
 +
[[Category:Architecture]]
 +
[[Category:Multi-Threading]]

Latest revision as of 07:12, 19 June 2007

Type: Effort State: 85% Owner: Kay Ramme

VCL (Visual Components Library) provides the OOo base widget set and windowing abstraction. It manages the event loop and dispatches the events. It also owns the display connection and manages various resources, e.g. fonts.

The goal of this effort is, to make VCL thread-transparent.

Problem

VCL hampers Thread-Transparency

VCL hampers thread-transparency in the following ways:

  • On Win32:
    • VCL is thread-affine under Windows - basically letting shine through the Win32 thread-affinity regarding window messages, window construction and window destruction.
    • VCL provides access to the main-thread, which basically is the thread which initializes VCL and which is expected to eventually enter the event-loop, on Win32.
    • VCL initializes the initiating threads apartment as STA on Win32. See gsl/vcl/source/app/svmain.cxx
  • VCL provides the Solar Mutex, which needs to be acquired before VCL can be called.
  • VCL completely releases the Solar Mutex in some situations, without any hints at the API.

VCLs internals are not protected against concurrent access, except by the Solar Mutex, which needs to be locked from the outside. VCLs API only provides blocking or polling functions for accessing the event loop, which is especially bad as it does not offer a way, to avoid long acquired MutExes, while waiting for events, except by actively polling.

Solution

Make VCL Thread-Transparent

To make VCL thread-transparent, we plan to

Support short MutEx Acquisition Times

To ensure short MutEx acquisition times, we plan to

  • add a system handle providing API, so that we can poll/select on the handle in an outer loop, and only need to enter VCL in case of pending events. Unfortunately, this seems to depend on the removal of the internal VCL event loop, so we may go with an interim solution.

Fix Side Effects

  • Some Win32 based OOo components (e.g. DDE) rely on their initializing thread to eventually enter the VCL event loop, to dispatch messages for objects created during this initialization. These implementations need to be adapted, to either delegate Win32 thread-affine calls into VCLs new internal thread, or to create a thread for dispatching purposes by their own.
  • With the removal of the Solar Mutex, VCL can not release a protecting MutEx anymore, which it currently does when executing a dialog. That means, that a protecting MutEx will stay acquired during presence of the dialog, basically disallowing other threads to enter VCL. This is going to be be addressed by making the office dialogs asynchronous and deprecating / removing the execute method.

Time Frame

At least the Effort/Encapsulate the Win32 thread affinity depends on Uno/Effort/Binary/Extend Threading-Model, therefor VCL thread-transparency will earliest be available after the bunoexttm CWS.

Tasks&CWS

Title State CWS Dependencies
Effort/Make Dialogs Asynchronous 75% asyncdialogs asyncdialogs2
Move Solar Mutex implementations (SalYieldMutex) into platform independent part. 0% vclYieldmutexReduction
Win32: Remove unnecessary "SendMessage" indirections in VCL backend. 0% vclYieldmutexReduction
Avoid releasing the Solar Mutex while being Application::Execute / Dialog::Execute 75% vclThreadTransparency asyncdialogs2
Win32: Encapsulate thread-affinity. 75% vclThreadTransparency bunoexttm
Fix "main-thread" API usages. These are thread-affinity workarounds only. open vclThreadTransparency
Win32: Fix (potential) implicit "GetMessage" dependencies. open vclThreadTransparency bunoexttm
Remove "main-thread-executor". open vclThreadTransparency
Remove "main-thread" access API (vcl/inc/svapp.hxx). open vclThreadTransparency
Create handle API. 75% vclThreadTransparency bunoexttm
Deprecate Application::Execute and Dialog::Execute. 75% vclThreadTransparency
Adapt soffice event-loop (desktop/source/app) to the handle API. 75% vclThreadTransparency
Win32: Simplify Drag&Drop and Clipboard by using Binary Unos extended threading model open vclSingleDispatch vclThreadTransparency
Remove Solar Mutex usages. open vclRetireSolarMutex vclThreadTransparency NewThreadingArch
Remove Solar Mutex (AKA YieldMutex) API and implementation. open vclRetireSolarMutex
Personal tools