This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFC: Too many race conditions.


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]