views:

71

answers:

3

HI Folks,

I have a threaded C++ program where up to three threads are calling select on a three separate socket descriptors waiting for data to become available. Each thread handles one socket and adds it to the readfds with a timeout of 300 seconds. After select returns if there is data available I'm calling recv to read it.

Is there anything that I need to be aware of with winsock and threads because for some reason after a number of hours the select calls all seem to be not timing out. Can a multi threaded program select from a number of threads without issue?

I know that I should have one thread listening to all three sockets however that would be a large change for this app and I'm only looking to apply a bug fix.

cheers,

Martin.

A: 

please post your code

Manuel
This should be a comment, not an answer.
John Dibling
Sorry I can't do that, my employer would not be pleased.
martsbradley
+1  A: 

Without some code, I can only make a guess. The most common reason for select timeouts to not work properly is that the struct timeval argument is not reset in every iteration of the loop. Some (all?) select implementations update the timeout parameter to reflect the amount of time spent blocking. However, this usually results in select not blocking.

Are you sure that select is the problem and you do not have something else going on like stack corruption, a memory leak, etc.?

Edit: I have used select from multiple threads on different sockets before under Windows without problems. I forgot to mention this in the initial post.

D.Shawley
The timeout structure is updated by select on a Linux machine, I've seen that before so I'm sure that I'm not repeating this problem.
martsbradley
A: 

Hi Folks,

I'm assuming that it is ok to use the select on differnet threads because the following link says it is grand.

http://tangentsoft.net/wskfaq/intermediate.html#threadsafety

martsbradley
This should be an edit to your OP, not a response to yourself.
John Dibling