C++ atomic operations for lock-free structures

前端 未结 2 1188
暖寄归人
暖寄归人 2020-12-08 11:45

I\'m implementing a lock-free mechanism using atomic (double) compare and swap instructions e.g. cmpxchg16b

I\'m currently writing this in assembly and then linking

相关标签:
2条回答
  • 2020-12-08 12:37

    Already kindof answered here.

    The C++0x standard will provide some atomic datatypes, mainly integer and void types using std::atomic<> template. That article mentions Boehm's atomic_ops project which you can download and use today.

    If not, can't you implement your assembler inline in the compiler? I know MSVC has the __asm keyword for inline assembler routines. Google says yes, gcc can do it too.

    0 讨论(0)
  • 2020-12-08 12:40

    The future "C++0x" standard for C++ will support atomic operations &c -- see e.g. http://www.open-std.org/JTC1/sc22/wg21/docs/papers/2007/n2427.html for a reasonably thorought discussion. Until said forthcoming standard is approved and widely implemented, of course, there's no way to get such functionality "portably" across compilers; if you're interested in specific compilers beyond gcc, maybe you can open another question specifically about them.

    0 讨论(0)
提交回复
热议问题