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.


Jeroen Frijters wrote:
David Daney wrote:
The only way to close the race window using user space synchronization
is to make the close block while you could be calling write().

That's not true. You can use ref counting to protect access to the fd and then close the fd when the ref count reaches zero. This way the actual native close can happen in any operation (read/write/close) or the finalizer, but is guaranteed only to happen when no other operation is in progress.


This is how .NET 2.0 does it. See http://blogs.msdn.com/cbrumme/archive/2004/02/20/77460.aspx for more information.

The semantics of files and pipes change if you don't close them when the application asks for them to be closed. In a pipe for example the read side would block waiting for the EOF. For a file, the filesystem containing the file could not be unmounted. Waiting for a potentially blocking I/O operation to finish before closing could cause deadlock. Also counting references requires obtaining some type of mutual exclusion lock twice for each I/O operation. This would add overhead to the current implementation.

We cannot cause a close operation to block where it currently does not. When the close call returns to the caller, we cannot still have the resource open.

David Daney

David Daney


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