Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 8 Jul 2008 12:48:53 -0400
From:      David Schultz <das@FreeBSD.ORG>
To:        Robert Watson <rwatson@FreeBSD.ORG>
Cc:        arch@FreeBSD.ORG, Poul-Henning Kamp <phk@phk.freebsd.dk>, Sergey Babkin <babkin@verizon.net>
Subject:   Re: Re: Re: Proposal: a revoke() system call
Message-ID:  <20080708164853.GA40704@zim.MIT.EDU>
In-Reply-To: <20080708161802.N89342@fledge.watson.org>
References:  <9484951.340521215467447990.JavaMail.root@vms126.mailsrvcs.net> <20080708001929.E63144@fledge.watson.org> <20080708161802.N89342@fledge.watson.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Jul 08, 2008, Robert Watson wrote:
> These sorts of edge cases, btw, are one reason why I would *strongly* 
> discourage application writers from doing things like calling close(2) on a 
> file descriptor while still using it from another thread. :-)

My reaction is that apps should use standard concurrency control
primitives, e.g., pthreads primitives or message queues, to
coordinate the activities of multiple threads. The are scads of
ways to introduce race conditions when updating various aspects of
the process state (the fd table, in this case). Once we start
adding special-purpose APIs to facilitate clever lock-free tricks
in very specific cases, when will it stop? Next we'll want a
special version of exit(), a special version of sigaction(), a
special version of free(), and so forth.

That said, POSIX does require open() and close() to be atomic, so
the Linux emulation layer should be fixed in that regard:

  2.9.7 Thread Interactions with Regular File Operations
  
  All of the functions chmod(), close(), fchmod(), fcntl(), fstat(),
  ftruncate(), lseek(), open(), read(), readlink(), stat(),
  symlink(), and write() shall be atomic with respect to each other
  in the effects specified in IEEE Std 1003.1-2001 when they operate
  on regular files. If two threads each call one of these functions,
  each call shall either see all of the specified effects of the
  other call, or none of them.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080708164853.GA40704>