Search code examples
c++c++11stdstdatomic

Implementing atomic<T>::store


I'm attempting to implement the atomic library from the C++0x draft. Specifically, I'm implementing §29.6/8, the store method:

template <typename T>
void atomic<T>::store(T pDesired, memory_order pOrder = memory_order_seq_cst);

The requirement states:

The order argument shall not be memory_order_consume, memory_order_acquire, nor memory_order_acq_rel.

I'm not sure what to do if it is one of these. Should I do nothing, throw an exception, get undefined behavior, or do something else?

P.S.: "C++0X" looks kinda like a dead fish :3


Solution

  • Do what you want. It doesn't matter.

    When ISO state that you "shall not do something", doing it is undefined behaviour. If a user does that, they have violated the contract with the implementation, and the implementation is within its rights to do as it pleases.

    What you decide to do is entirely up to you. I would opt for whatever makes your implementation "better" (in your eyes, be that faster, more readable, subject to the principle of least astonishment, and so forth).

    Myself, I'd go for readability (since I would have to maintain the thing) with speed taking a close second.