Boost C++ Libraries: Ticket #6782: call_once uses incorrect barrier intrinsic on Visual Studio https://svn.boost.org/trac10/ticket/6782 <p> boost\thread\win32\interlocked_read.hpp uses _ReadWriteBarrier() as a barrier. However, <a class="ext-link" href="http://msdn.microsoft.com/en-us/library/f20w0x5e%28v=vs.100%29.aspx"><span class="icon">​</span>according to MSDN</a> and the machine code generated, it doesn't emit any memory barrier instructions at all: </p> <blockquote class="citation"> <p> The _ReadBarrier, _WriteBarrier, and _ReadWriteBarrier compiler intrinsics prevent only compiler re-ordering. To prevent the CPU from re-ordering read and write operations, use the <a class="missing wiki">MemoryBarrier</a> macro. </p> </blockquote> <p> So one should use the <a class="missing wiki">MemoryBarrier</a>() macro instead. In fact according <a class="ext-link" href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms684208%28v=vs.85%29.aspx"><span class="icon">​</span>this page</a> _ReadWriteBarrier is not necessary for volatile variables access since VS2005. </p> <p> Thanks, </p> <ol class="upperalpha" start="25"><li>Galka. </li></ol> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6782 Trac 1.4.3 viboes Mon, 28 May 2012 15:54:13 GMT owner, status changed https://svn.boost.org/trac10/ticket/6782#comment:1 https://svn.boost.org/trac10/ticket/6782#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">viboes</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> Could you provide a test that proves the issue. And a patch to solve it? </p> Ticket viboes Sun, 03 Mar 2013 23:18:08 GMT <link>https://svn.boost.org/trac10/ticket/6782#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6782#comment:2</guid> <description> <p> wouldn't be enough to remove these lines and let the implementation using boost/detail/interlocked.hpp? </p> <pre class="wiki">#ifdef BOOST_MSVC extern "C" void _ReadWriteBarrier(void); #pragma intrinsic(_ReadWriteBarrier) namespace boost { namespace detail { inline long interlocked_read_acquire(long volatile* x) BOOST_NOEXCEPT { long const res=*x; _ReadWriteBarrier(); return res; } inline void* interlocked_read_acquire(void* volatile* x) BOOST_NOEXCEPT { void* const res=*x; _ReadWriteBarrier(); return res; } inline void interlocked_write_release(long volatile* x,long value) BOOST_NOEXCEPT { _ReadWriteBarrier(); *x=value; } inline void interlocked_write_release(void* volatile* x,void* value) BOOST_NOEXCEPT { _ReadWriteBarrier(); *x=value; } } } #else #endif </pre><p> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Niall Douglas</dc:creator> <pubDate>Sat, 04 Oct 2014 18:49:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6782#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6782#comment:3</guid> <description> <p> I believe Boost requires VS2005 minimum now, so I have removed the <a class="missing wiki">ReadWriteBarrier</a> completely as volatile reads always acquire and volatile writes always release. MSVC generates the appropriate acquire-release opcodes on ARM, and on x86 they are unnecessary as all loads acquire and all stores release. This ticket can now be closed. Niall </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 05 Oct 2014 06:49:13 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/6782#comment:4 https://svn.boost.org/trac10/ticket/6782#comment:4 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.57.0</span> </li> </ul> <p> <a class="ext-link" href="https://github.com/boostorg/thread/commit/6fe7f44ea047b5f4c0182fa73fb1755af0bcf11a"><span class="icon">​</span>https://github.com/boostorg/thread/commit/6fe7f44ea047b5f4c0182fa73fb1755af0bcf11a</a> </p> Ticket viboes Sat, 11 Oct 2014 05:22:52 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/6782#comment:5 https://svn.boost.org/trac10/ticket/6782#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> <a class="ext-link" href="https://github.com/boostorg/thread/commit/6fe7f44ea047b5f4c0182fa73fb1755af0bcf11a"><span class="icon">​</span>https://github.com/boostorg/thread/commit/6fe7f44ea047b5f4c0182fa73fb1755af0bcf11a</a> </p> Ticket