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.


mark@mark.mielke.cc wrote:
On Sun, May 20, 2007 at 07:48:11PM -0700, David Daney wrote:
It is not socket or java specific. I think of it as a defect in Posix (reuse of the lowest numbered descriptor possible).

Perhaps exacerbated by POSIX. Unless handles are guaranteed to be unique throughout the existence of a process, any reduction in re-use would only narrow the window. It would not eliminate it. Consider the old malloc() implementation that would purposefully not re-use recently free()d memory. This allowed people to write code that would continue to use memory after it had been free()d. Good, or bad? The same would be true of allowing people to use file descriptors after they have been closed.

In any case - I appreciated your suggested solution. The dup2() to
perform a close of the socket was clever, leaving a garbage file
descriptor in its place. Still, the overhead appears to be high as
you noted.
All the overhead is due to synchronizing to ensure that the "garbage file descriptor" gets cleaned up. An alternative would be to clean up the "garbage file descriptor" in a finalizer. That way no synchronization would be necessary except in close(). The drawback of this approach is that idioms that kept closed Streams around a long time could leak descriptors.

David Daney


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