RFC: Too many race conditions.

mark@mark.mielke.cc mark@mark.mielke.cc
Mon May 21 15:12:00 GMT 2007


On Mon, May 21, 2007 at 08:01:01AM -0700, David Daney wrote:
> Andrew Haley wrote:
> > [ compare and swap the file descriptor out during write() & close() ]
> The only way to close the race window using user space synchronization 
> is to make the close block while you could be calling write().

Agree, Dave. Andrew: Dave's dup2() trick makes use of the kernel to
work around this. For user space, it's only possible to narrow the
window, or change behaviour. In terms of narrowing the window, an
approach that used a sempahore or atomic integer might work. I don't
think compare and swap would work, as that would seem to have the
effect of restricting I/O operations to one thread at a time - or
serializing I/O operations to one at a time. What if I want to
accept() from multiple threads?

> Consider the case where you are doing a blocking read().  The 
> synchronization would cause close() to block until the read() had 
> finished.  This is not allowed for nio Channels.  The close has to 
> terminate the read operation.

Yes.

Cheers,
mark

-- 
mark@mielke.cc / markm@ncf.ca / markm@nortel.com     __________________________
.  .  _  ._  . .   .__    .  . ._. .__ .   . . .__  | Neighbourhood Coder
|\/| |_| |_| |/    |_     |\/|  |  |_  |   |/  |_   | 
|  | | | | \ | \   |__ .  |  | .|. |__ |__ | \ |__  | Ottawa, Ontario, Canada

  One ring to rule them all, one ring to find them, one ring to bring them all
                       and in the darkness bind them...

                           http://mark.mielke.cc/



More information about the Java mailing list