Advertisement

Blocking in a thread?

Started by March 26, 2002 08:00 PM
2 comments, last by Lohrno 22 years, 10 months ago
Is it okay to do a blocking call to a receive function if your network code is in another thread? Or are there some kind of consequences to that? -=Lohrno
If you have several socket and your network thread is blocked waiting for data from one of them, it will not process the other sockets, even though they may have data and would not block.

One solution is to have your thread block on select() instead : select returns once at least one of the sockets in the set you give it can be read/written to.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
If each socket has its own thread, then it''s not a problem.
Unless you have a lot of sockets open
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement