0

I was trying to follow the queue implementation in this blog that uses a memory barries like below:

asm volatile ("" ::: "memory");

But the same is not working for me and throwing this error:

error C2589: ':': illegal token on right side of '::'

How to express the same memory barrier in c++11?

Ðаn
  • 10,934
  • 11
  • 59
  • 95
Sayantan Ghosh
  • 998
  • 2
  • 9
  • 29
  • 3
    That looks like an MSVC error message, can you confirm? And that's GCC inline assembly, so it won't work with MSVC. – harold Aug 07 '21 at 16:34
  • Yes MSVC - what is the MSVC equivalent to achieve the same? – Sayantan Ghosh Aug 07 '21 at 16:35
  • 2
    This notation for inline assembly is for the gcc compiler and other compilers that maintain compatibility with it - notably clang and the intel compilers. Microsoft compilers have their own syntax for inline assembly. – Brett Hale Aug 07 '21 at 16:36
  • 1
    @SayantanGhosh - see this question: [C++ Memory Barriers for Atomics](https://stackoverflow.com/questions/8841738/c-memory-barriers-for-atomics). A more recent list of intrinsics (better than using asm when available) is listed [here](https://learn.microsoft.com/en-us/cpp/intrinsics/x64-amd64-intrinsics-list). These documents in turn suggest using [`atomic_thread_fence`](https://learn.microsoft.com/en-us/cpp/standard-library/atomic-functions?view=msvc-160#atomic_thread_fence) from `` facilities. – Brett Hale Aug 07 '21 at 16:50
  • 2
    That whole blog is written using gcc intrinsics which won't work at all in MSVC. In this day and age I would think you'd want to use `` instead. The author complains that gcc doesn't optimize the `` functions well enough, but that's based on a very old version, and you're not using gcc anyway. Maybe you want to see if you can find a more up-to-date implementation. – Nate Eldredge Aug 07 '21 at 19:00

0 Answers0