I have following problem with threads synchronization (in Win2000)
The main thread (let's say thread A) creates two separate threads
(thread B and C), which implements window registration and creation.
In threads B and C then runs the window message looping. These windows
(running in threads B and C) are used for treating SOCKETs messages
(FD_READ, FD_CONNECT etc). Of course, sockets are put in asynchornous
Then, in main thread A I do following ...
HANDLE syncObject = CreateEvent(NULL, TRUE, FALSE, NULL);
PostMessage(hSocketWndThreadB, WM_SEND_PACKAGE, (WPARAM)packagePtr,
Event syncObject will be signaled, when an answer from server will
arrive so I want to wait for server reply (or error of course)
(calling of SetEvent(syncObject) is implemented in thread B, after the
server reply is received).
Everything looks fine, message WM_SEND_PACKAGE is sent to appropriate
window and package is sent (socket method "send" returns the size of
package). The problem is with calling the WaitForSingleObject
function. When I do this, all threads look to be blocked (ie. not only
thread A, but also thread B and C).
Why ? Can U please explain me, why threads B and C are blocked too ?
To test, that threads B and C are blocked I used following method:
I created timers on windows, which are implemented in thread B and C
in thread B I called SetTimer(hSocketWndThreadB, 1, 1000, NULL) and in
thread C I called SetTimer(hSocketWndThreadC, 2, 1500, NULL). When
message WM_TIMER has arrived, i called MessageBeep(...). I noticed,
that after WaitForSingleObject in thread A system stoped sending of
WM_TIMER messages that it looks like threads B and C are blocked too.
Thank you for any help or explanaition of this synchronization