Re: CLONE_FILES problem.

Steven S. Dick (ssd@nevets.oau.org)
Wed, 21 Aug 96 20:18 EDT


Tom May <alfred!ucf-cs!netcom.com!ftom> wrote:
>I recently wrote a device driver for NeXTSTEP in which a close() from
>one thread forces an EBADF error on any pending reads in other
>threads. This was ideal behaviour for the application I was
>supporting, but I have no idea whether it would be a good thing in the
>general case.

No, this is not the right thing to do in the general case.
Let's assume for a moment that the programmer isn't so stupid as to
need protection by the system...

What if the programmer has a thread that does nothing but close unused
files and open needed files.... and another thread that does nothing
but handle read requests in a queue. It might mark a file as "finished"
and the close thread would then close it, and open another file...
The read thread might then notice and read again from the same fd,
with the desire to get data from the new file.

How do you propose the read thread should tell the kernel that it wants
the new file instead of the old one? Open the file itself??

If a thread is using a file while another thread closes it, it is a
programming error. Nothing special should be done about this except
that the kernel shouldn't fault because of a race condition in buggy code.

Steve
ssd@nevets.oau.org