FindWindow, WaitforSingleObject and Deadlock

Uwe Bonnes bon at
Sun Oct 28 11:49:10 CST 2001


I reported before, some applications of the quicklogic suite starts some
watchdog application and hangs at this state. I tracked this down to the
following sequence of events:

- master application starts, sets up an event and resets the event
- master application starts the watchdog
- as soon as CreateProcess return, the Master application calls
  WaitForSingleObject with infinite timeout on that event
- watchdog application starts and calls FindWindow. This is translated in a
  GetWindowText Call and finally  SendMessageW (WM_GETTEXT) is called
- Master application never awakes from waiting for the WaitForSingleObject
  Event and so never processes the SendMessage and Findwindow in the watchdog
  never returns

I found two things relates to this deadlock in the API description:
For 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"

so the latter behaviour seems right. But GetWindowText seems to expect such a 
"If the target window is owned by the current process, GetWindowText causes a
WM_GETTEXT message to be sent to the specified window or control. If the
target window is owned by another process and has a caption, GetWindowText
retrieves the window caption text. If the window does not have a caption, the
return value is a null string. This behavior is by design. It allows
applications to call GetWindowText without hanging if the process that owns
the target window is hung."

Sending the WM_GETTEXT only for local windows in the FindWindow loop makes the
application continue and at some point the event is triggered.

How should wine handle that case? Sould the caption be stored on the server? I
it perhaps already?


Uwe Bonnes                bon at

Free Software: If you contribute nothing, expect nothing

More information about the wine-devel mailing list