I'm having trouble performing a search operation in the background, and displaying the results to the user in the foreground inside a list box.
The program uses SendMessage
to send the query results back to the GUI.
When the program is closed, the GUI marks a global (volatile) variable as "completed", and uses MsgWaitForMultipleObjects
to wait on the thread handle, to join the thread.
When I break the program, I see a deadlock: the GUI is waiting for the background thread to terminate, whereas the background thread is waiting in SendMessage
.
This deadlock still occurs when I use a 100-ms timeout for MsgWaitForMultipleObjects
and call it inside a loop, with QS_ALLINPUT
. I can't figure out why.
Is this design even correct? Is there a better way to wait for the thread to terminate?
If not, what is the issue?