Add text cautioning about use of close() in

multithreaded programs.
This commit is contained in:
Michael Kerrisk 2007-09-13 19:38:28 +00:00
parent 0a1a55e0b1
commit aadd727c4f
1 changed files with 15 additions and 0 deletions

View File

@ -104,6 +104,21 @@ If you need to be sure that
the data is physically stored use
.BR fsync (2).
(It will depend on the disk hardware at this point.)
.PP
It is probably unwise to close file descriptors while
they may be in use by system calls in
other threads in the same process.
Since a file descriptor may be re-used,
there are some obscure race conditions
that may cause unintended side effects.
.\" Date: Tue, 4 Sep 2007 13:57:35 +0200
.\" From: Fredrik Noring <noring@nocrew.org>
.\" One such race involves signals and ERESTARTSYS. If a file descriptor
.\" in use by a system call is closed and then reused by e.g. an
.\" independet open() in some unrelated thread, before the original system
.\" call has restared after ERESTARTSYS, the original system call will
.\" later restart with the reused file descriptor. This is most likely a
.\" serious programming error.
.SH "SEE ALSO"
.BR fcntl (2),
.BR fsync (2),