Solarmutex Deadlock when Closing Calc which contains functions with XVolatileResult return values

Stephan Bergmann sbergman at
Thu Aug 16 01:09:13 PDT 2012

On 08/15/2012 04:58 PM, anwen wrote:
> A brief summary of this discussion: My purpose is to develop a Calc
> extension based on LibreOffice environment. As an extension, it registers
> itself as a UNO component and provides some add-in functions which retrieve
> streaming data. This extension object builds connections via worker threads
> to an outside streaming data server. Everything runs well until I terminate
> the LibreOffice with x click: Soffice.bin/Soffice.exe are still alive after
> the termination process is completed and all the documents are closed.  It
> happens when the worker threads try to update the spreadsheet using
> modified() function and the termination process tries to stop the worker
> threads. SolarMutex may be the reason of this issue.
> To solve the issue, I implemented two interfaces: XTerminationListener and
> XEventListener. The former listens to desktop.termination. The latter
> listens to document events. From my observation, the worker thread could be
> blocked within modified() forever by queryTermination() and
> notifyTermination(). It could also be blocked forever by some documents
> events, like OnPrepareViewClosing, OnPrepareUnload, OnViewClosed, OnUnload,
> OnUnfocus, and OnCloseApp. Interestingly, I observed that the worker thread
> could resume running when seeing OnModeChanged event.

So the situation is as follows:  When your notifyTermination() listener 
is called (which apparently happens with the SolarMutex being locked), 
you need to synchronously terminate and join your worker thread.  But at 
that time your worker thread happens to be blocked waiting for the 
SolarMutex, at some stack frame nested in a call to some modified() 
(which is part of your code).  Right?  (Can you make available the 
source code of your extension?)

I still see no true fix short of having the notifyTermination listeners 
being fired without SolarMutex locked.

> Currently, my workaround with the SolarMutex issue is double termination
> 'x'' clicks: first termination is vetoed in queryTermination() where I setup
> status change to avoid modified(). Then the second termination will kill all
> the threads and the LibreOffice process. Right now, I did double
> terminations manually. I am wondering if I could manipulate OnModeChanged
> events which may solve the issue too. Although the spreadsheet shows dynamic
> data with XVolatileResult return type, it does not popup save dialogue if I
> open an existing calc file.

So, you manually need to click the 'X' to close the LibreOffice window 

And where do you call the code to terminate and join your worker thread 
now?  (Or do you not call such code at all, and things appear to work by 
chance, due to changes in timing?)


More information about the LibreOffice mailing list