Hi Eike, Thank you for your advices. After doing some research, I decided to use XTerminateListener which is registered with the LibreOffice desktop. The reason is that once the Calc extension gets started, it is alive until the desktop termination. So does the worker thread associated with the Extension.
With the TerminateListener, I successfully get the desktop termination event by queryTermination() function. Although you told me that I could veto this termination signal by throwing TerminationVetoException. I am not sure how and where to handle the TerminationVetoException and re-call XDesktop.terminate() to finally close the office. So I tried to handle everything inside queryTermination(). Here is my code: void SAL_CALL CalcTerminateListener::queryTermination(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException ) { if (realtime_session) { std::cout << "will close real time session" << std::endl; realtime_session->stop(); std::cout << "closed real time session" << std::endl; } } However, deadlock happened sometimes again. Here is my analysis: this function is called by the main thread and is protected by the SolarMutex. If a modified() function is called by the worker thread at the same time, the worker thread is waiting for the SolarMutex. Then the main thread tries to stop the worker thread by calling realtime_session->stop(). This session is designed with thread safe strategy by a third-party. It fails to close the worker thread because the worker thread is waiting for the Main thread to release the SolarMutex. Since the SolarMutex is everywhere, do you have any suggestion to clear it for a while and give a chance to close the worker thread? or How and where to handle the TerminationVetoException. It is not clear in the Developer's guide. Thank you very much. In case that someone is interested with registration of terminatelistener. Here is my code: ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xCC; // it is assigned when initializing the extension. xDesktop(m_xCC->getServiceManager()->createInstanceWithContext(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop")), m_xCC), UNO_QUERY); if (!xDesktop.is()) { std::cout << "failed to find the desktop" << std::endl; return; } Reference<XTerminateListener> myListener = new CalcTerminateListener(&blp_conn); xDesktop->addTerminateListener(myListener); std::cout << "added an TerminateListener" << std::endl; BTW, I am not sure how to initialize a XDocumentEventBroadcaster which you mentioned previously in a Calc Extension. I tried this method: Reference<XSpreadsheetDocument> xCalc(m_xCC->getServiceManager()->createInstanceWithContext(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SpreadsheetDocument")), m_xCC), UNO_QUERY); But it did not work. Thank you for any suggestion. Best, Wendi Eike Rathke-2 wrote > > Hi anwen, > > On Wednesday, 2012-08-01 07:57:00 -0700, anwen wrote: > >> Here is a minor remind that modified() is a method >> of XResultListener (not XVolatileResult). > > Bah, yes, of course, thanks. > >> It is implemented in Calc by SCAddInListener class. > > I know, see my .signature below ;-) > > Eike > > -- > LibreOffice Calc developer. Number formatter stricken i18n > transpositionizer. > GnuPG key 0x293C05FD : 997A 4C60 CE41 0149 0DB3 9E96 2F1A D073 293C 05FD > > _______________________________________________ > LibreOffice mailing list > LibreOffice@.freedesktop > http://lists.freedesktop.org/mailman/listinfo/libreoffice > -- View this message in context: http://nabble.documentfoundation.org/Solarmutex-Deadlock-when-Closing-Calc-which-contains-functions-with-XVolatileResult-return-values-tp3998056p3999984.html Sent from the Dev mailing list archive at Nabble.com. _______________________________________________ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice