Re: WSAyncSelect in Multithreading
Phanidhar wrote:
This is common in all windows programs and not unique to socket
messages. What you have done is reenter the message loop from another
message handler so, naturally, the wndProc can then reenter. Example:
http://www.codecomments.com/message824900.html
Then if I understand it corectly, if I get multiple socket notifications,
each notification calls the message loop independently and therefore the
wndproc is re-entered. Now if I want to avoid this, can I make use of some
synchronization mechanism like mutex to make sure that wndproc is not
reentered?
No, that's kind of upside down. The socket notifications don't call the
message loop, only your code calls the message loop. Socket
notifications merely put a message into the queue. It waits there until
you call the message loop. So you are in charge.
The only way to avoid reentry by a second socket notification is to not
call the message loop (or anything like MessageBox that runs another
message loop) from your FD_READ message handler.
It's very simple: Your FD_READ message handler should grab the data
without calling any GUI stuff, then return. If you need to execute GUI
stuff do it later: You can call PostMessage in your FD_READ message
handler, then do the GUI interaction later in response to your posted
message.
--
Scott McPhillips [VC++ MVP]