diff --git a/integer.cpp b/integer.cpp index 949d6890..35f22698 100644 --- a/integer.cpp +++ b/integer.cpp @@ -3011,21 +3011,27 @@ struct NewInteger } }; +// File scope static due to subtle initialization problems in a threaded +// Windows environment. See the comments for Singleton. Thanks DB. +static const Integer& s_zero = Singleton().Ref(); const Integer &Integer::Zero() { - static const Integer& s_zero = Singleton().Ref(); return s_zero; } +// File scope static due to subtle initialization problems in a threaded +// Windows environment. See the comments for Singleton. Thanks DB. +static const Integer& s_one = Singleton >().Ref(); const Integer &Integer::One() { - static const Integer& s_one = Singleton >().Ref(); return s_one; } +// File scope static due to subtle initialization problems in a threaded +// Windows environment. See the comments for Singleton. Thanks DB. +static const Integer& s_two = Singleton >().Ref(); const Integer &Integer::Two() { - static const Integer& s_two = Singleton >().Ref(); return s_two; } diff --git a/misc.h b/misc.h index 7a9cbd68..21c3f39d 100644 --- a/misc.h +++ b/misc.h @@ -257,9 +257,12 @@ struct NewObject //! \details This class safely initializes a static object in a multithreaded environment. For C++03 //! and below it will do so without using locks for portability. If two threads call Ref() at the same //! time, they may get back different references, and one object may end up being memory leaked. This -//! is by design. For C++11 and above, a standard double-checked locking pattern with thread fences +//! is by design and it avoids a subltle initialization problem ina multithreaded environment with thread +//! local storage on early Windows platforms, like Windows XP and Windows 2003. +//! \details For C++11 and above, a standard double-checked locking pattern with thread fences //! are used. The locks and fences are standard and do not hinder portability. -//! \sa Double-Checked Locking is Fixed In C++11 +//! \sa Double-Checked +//! Locking is Fixed In C++11 template , int instance=0> class Singleton {