c++ - Why does atomic_flag.clear() have a sub-optimal default memory_order argument? -
std::atomic_flag
has 2 functions these default std::memory_order
s:
void clear(std::memory_order order = std::memory_order_seq_cst); bool test_and_set(std::memory_order order = std::memory_order_seq_cst);
perhaps i'm wrong, shouldn't clear
always memory_order_release
, test_and_set
always memory_order_acquire
? maybe misunderstand these do.
the default memory order sequential consistency (std::memory_order_seq_cst
) atomic operations in c++11. can specify more relaxed memory order if want, although more complicated reason about.
the std::atomic_flag
garanteeded lock-free , can used build other synchronization methods. whereas std::atomic<t>
types can implemented locks if compiler/library writer chooses , still conform specification. why std::atomic_flag
exists these defaults. depending on trying might make sense specify different memory order defaults set conservatively correct sequential consistency.
Comments
Post a Comment