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