How to perform atomic operations on Linux that work on x86, arm, GCC and icc?

前端 未结 9 1553
無奈伤痛
無奈伤痛 2020-12-02 11:52

Every Modern OS provides today some atomic operations:

  • Windows has Interlocked* API
  • FreeBSD has
9条回答
  •  [愿得一人]
    2020-12-02 12:52

    Projects are using this:

    http://packages.debian.org/source/sid/libatomic-ops

    If you want simple operations such as CAS, can't you just just use the arch-specific implementations out of the kernel, and do arch checks in user-space with autotools/cmake? As far as licensing goes, although the kernel is GPL, I think it's arguable that the inline assembly for these operations is provided by Intel/AMD, not that the kernel has a license on them. They just happen to be in an easily accessible form in the kernel source.

提交回复
热议问题