Boost C++ Libraries: Ticket #11514: Thread-unsafe (or non-optimal in C++11) static initialization in boost/spirit/home/qi/numeric/detail/numeric_utils.hpp https://svn.boost.org/trac10/ticket/11514 <p> This file (it's the same in boost 1.58 which I have too): boost/spirit/home/qi/numeric/detail/numeric_utils.hpp has following code (similar in a couple of places): </p> <pre class="wiki">// Ensure n *= Radix will not overflow static T const max = (std::numeric_limits&lt;T&gt;::max)(); static T const val = max / Radix; </pre><p> Since static initialization is not thread-safe in Visual Studio (the one I'm using now is 2013 update 4), and because these variables are dependent on each other, this causes problems. Indeed, sometimes I get <strong>val</strong> initialized to 0, and other times to correct value. </p> <p> But even when "magic statics" are implemented, this will probably be not the most efficient implementation since a better one would be using, say, constexpr. </p> <p> There are couple of ways to fix this, and one with minimal changes (considering my minimal knowledge of boost constexpr machinery) would be: </p> <pre class="wiki">// ## Note how two variables are initialized independently. static T const max = (std::numeric_limits&lt;T&gt;::max)(); static T const val = (std::numeric_limits&lt;T&gt;::max)() / Radix; </pre><p> Thanks! </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11514 Trac 1.4.3 Joel de Guzman Tue, 28 Jul 2015 00:08:25 GMT <link>https://svn.boost.org/trac10/ticket/11514#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11514#comment:1</guid> <description> <p> Makes sense. Could you please provide a pull request here: <a class="ext-link" href="https://github.com/boostorg/spirit/tree/develop"><span class="icon">​</span>https://github.com/boostorg/spirit/tree/develop</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Sat, 24 Nov 2018 05:10:22 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11514#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11514#comment:2</guid> <description> <p> fixed in <a class="ext-link" href="https://github.com/boostorg/spirit/pull/146"><span class="icon">​</span>https://github.com/boostorg/spirit/pull/146</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Sat, 24 Nov 2018 05:10:39 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/11514#comment:3 https://svn.boost.org/trac10/ticket/11514#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket