Huaidong Qiu wrote:
Hi all,

dtrans\source\win32\dnd\target.cxx

I encountered a freeze problem recently, the office freezed in function
DropTarget::initialize

void SAL_CALL DropTarget::initialize( const Sequence< Any >& aArguments )
        throw(Exception, RuntimeException)
{

..........
            m_hOleThread= CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)
DndTargetOleSTAFunc,
                                            &m_evtThreadReady, 0,
&m_threadIdTarget);
            WaitForSingleObject( m_evtThreadReady, INFINITE);

..........
}

After several days investigation, I think the maybe the function
WaitForSingleObject is missused.

If DropTarget::initialize called from a STA thread, the wait function
WaitForSingleObject() should not be used, because this wait will block the
message pumping of the thread, all COM calls will be blocked, this could
lead to a freeze.

Quote from the API document of WaitForSingleObject:

Use caution when calling the wait functions and code that directly or
indirectly creates windows. If a thread creates any windows, it must process
messages. Message broadcasts are sent to all windows in the system. A thread
that uses a wait function with no time-out interval may cause the system to
become deadlocked. Two examples of code that indirectly creates windows are
DDE and the *CoInitialize* function.
Therefore, if you have a thread that creates windows, use
*MsgWaitForMultipleObjects* or *MsgWaitForMultipleObjectsEx*,
rather than *WaitForSingleObject*.

I think we should use CoWaitForMultipleHandles(), which is a wrapper for
MsgWaitForMultipleObjects(), after I switched to CoWaitForMultipleHandles(),
app did not freeze in DropTarget::initialize anymore.

And this issue also mentioned in this MSDN tech article The Rules of the
Component Object Model, in the section Apartment Threading Model

http://msdn.microsoft.com/en-us/library/ms810016.aspx

Hi Huaidong,

I think your findings look convincing. I am not the maintainer of the project and therefore cannot approve your changes. Do you know what thread calls DropTarget::initialize? Is this the main thread (the thread that normally executes the message loop?

Regards,
Carsten

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@gsl.openoffice.org
For additional commands, e-mail: dev-h...@gsl.openoffice.org

Reply via email to