1

I'm using __sync_xxx functions to implement lock-free queue.

However, I've noticed that they are legacy, and there are __atomic functions, which are introduced in GCC 4.8.

I read the page, and noticed the difference: __atomic requires "memory model".

__ATOMIC_RELAXED No barriers or synchronization.

__ATOMIC_CONSUME Data dependency only for both barrier and synchronization with another thread.

__ATOMIC_ACQUIRE Barrier to hoisting of code and synchronizes with release (or stronger) semantic stores from another thread.

__ATOMIC_RELEASE Barrier to sinking of code and synchronizes with acquire (or stronger) semantic loads from another thread.

__ATOMIC_ACQ_REL Full barrier in both directions and synchronizes with acquire loads and release stores in another thread.

__ATOMIC_SEQ_CST Full barrier in both directions and synchronizes with acquire loads and release stores in all threads.

But I can't understand what is.. Could you explain me, with practical example?

2
  • You should go with the default, which should be the most restrictive. The others are useful only, if you want to squeeze some extra performance. There are literally whole books written about this topic. Try starting here. May 25, 2014 at 9:09
  • @Banthar Actually, the queue is used in a crucial part of my operating system's kernel; so the fast the better. Thank you for you advice.
    – ikh
    May 25, 2014 at 9:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.