[Boost-bugs] [Boost C++ Libraries] #5752: boost::call_once() is unreliable on some platforms

Subject: [Boost-bugs] [Boost C++ Libraries] #5752: boost::call_once() is unreliable on some platforms
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-08-04 21:36:44


#5752: boost::call_once() is unreliable on some platforms
---------------------------------------------------+------------------------
 Reporter: Matthew Dempsky <matthew@…> | Owner: anthonyw
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: threads
  Version: Boost 1.47.0 | Severity: Problem
 Keywords: |
---------------------------------------------------+------------------------
 boost::call_once() is an implementation of Mike Burrows's
 fast_pthread_once() algorithm, as described in http://www.open-
 std.org/jtc1/sc22/wg21/docs/papers/2008/n2660.htm. In the correctness
 proof, there is a requirement that loads and stores of the epoch value are
 atomic (i.e., do not exhibit word tearing). In Mike's example
 implementation, the sig_atomic_t type is used, which is required by the C
 standard to support atomic loads and stores.

 However, in the boost::call_once() implementation, the epoch value is
 defined as uintmax_t, which has no such guarantee, and in practice is not
 atomic on some architectures. E.g., on OpenBSD/i386, uintmax_t is a
 64-bit type and assignments to a 64-bit memory address must be split into
 two (non-atomic) store instructions.

 Therefore, thread/pthread/once.hpp should be changed to use a type that is
 guaranteed to support atomic loads and stores instead of uintmax_t.
 Additionally, since once_flag::epoch is accessed by multiple threads
 without any synchronization, it should be marked volatile.

 (Alternatively, the new C++0x atomic operations library appears suitable
 for this use as well.)

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5752>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:07 UTC