From aadd727c4f89ea73bda4e09a5aedc35432deb778 Mon Sep 17 00:00:00 2001 From: Michael Kerrisk Date: Thu, 13 Sep 2007 19:38:28 +0000 Subject: [PATCH] Add text cautioning about use of close() in multithreaded programs. --- man2/close.2 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/man2/close.2 b/man2/close.2 index 43bf751e8..10a2c4a47 100644 --- a/man2/close.2 +++ b/man2/close.2 @@ -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 +.\" 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),