[Spread-users] Question about thread-safety

George Schlossnagle george at omniti.com
Mon Jun 16 17:47:45 EDT 2003


On Monday, June 16, 2003, at 05:38  PM, John Schultz wrote:

>
>>> NOTE: if anyone knows how to instruct Unix/Linux systems not to reuse
>>> file descriptor IDs in a process, could you please email me or the 
>>> list
>>> a good reference (with page #)? Thanks!
>
>> It is part of the guaranteed semantics of open() that it returns the
>> lowest available file descriptor, so there's definitely no way to do
>> this unless you simply keep it open.
>
> Doesn't this cause a general race condition in multi-threaded 
> Unix/Linux
> applications that open and close file descriptors in multiple threads?
>
> The race condition: a thread is about to operate on file descriptor x, 
> but
> just before it does another thread(s) close x and create a new file
> descriptor which is assigned the same value as x.
>
> To avoid this race condition wouldn't all calls that create and/or 
> close
> file descriptors have to be done in a single thread that ensures no 
> other
> threads are operating on any file descriptors it is about to close? If 
> so,
> that seems like a BAD thing to me.

Why can't you use a mutex to protect these sorts of accesses? 





More information about the Spread-users mailing list