Re: Multithread select() bug

From: Andre Ben Hamou
Date: Mon May 10 2004 - 18:11:30 EST


Eric Dumazet wrote:
So please how do you guarantee that thread 1 runs *before* thread 2)

Thread 1)
select( fd)

Thread 2)
close(fd)

Thats not possible.


I see where you're coming from, in that there is a potential race condition as to the socket being connected as I reach the select call.

This is an important concern but it is, I think, orthogonal to the original problem as there are two possible socket states at the point at which select gets called (as far as I can see)...

1. The socket is in its connected state
2. The socket has already been closed by the parent thread

As I understand it, if 1 is true (which corresponds to my original post), then select should return the moment the socket gets closed and, if 2 is true (which I believe corresponds to your concern), then select should return immediately anyway as the socket would not block if read from.

Sorry to be a pest, but I'm trying to get this clear in my head. Is it possible I've over-estimated the thread-safety of the select and close calls?

Cheers,

Andre Ben Hamou
Imperial College London

--

...and, on the seventh day, God switched off his Mac.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/