Winsock2 Threads blocking each other

hi guys,

i have a program with two threads. Both of them use a Winsock2 udp socket to send data. Now it seems that on one of the pc's the sending thread is blocking the receiving thread. the two connections are running over different sockets and different ports. the two threads are sharing no data whatsoever. they run completly isolated from each other and are working fine when i run them seperately. i am really running out of ideas how this is possible.

any guesses ?
On the PC that's hanging:
1. run the program in a debuggger
2. break into the program when it's deadlocked
3. Inspect the call stack for each of the deadlocked threads

Look at the function parameters, local variables to try to work out what is being sent, and what reply is being expected.

You'll also need a log of what the other PC is doing.

I can't say any more because you haven't described what you're actually doing or posted any code.
yes sorry,

now i can say for sure that the remote pc is still sending data. but my pc here stops receiving as soon as the second thread (sending data) starts to work. he hangs at the recv (winsock2) function. like it would be waiting for packages.

is it possible that the second thread just uses up all the bandwith ?
both threads use 1 message pump, so they both use WM_SOCKET. How do you split work? Do you know that winsock functions are not thread safe?

1 thread with pump ---on recieve-->push msg on queue
<-----------go back at set some receive event---

working threads should sleep (waitforsingleobject) until receive event is set. When it does wake up, it should pop msg from queue and process it. Key here is to put critical sections in pop and push functions to access queue.
Last edited on
yes i know that winsock is not thread safe. that's why i use two different sockets and ports for the two connections. maybe i was not clear enought: the two threads do NOT interact. they are running seperately. one is sending data, one is receiving other data.

now i get a WSAEINVAL error from the recvfrom function as soon as the second thread starts. the microsoft site says that happens when the socket is not bound. but it was bound before or it wouldnt work to begin with right ?
You're using threads, right? So why are you using that message based nonsense that WinSock offers?

Just stick the the basic BSD socket calls.
Topic archived. No new replies allowed.