Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't std::atomic_is_lock_free a static constexpr?

Tags:

c++

c++11

atomic

I am confused. How is it possible that implementation may know if type is atomic only at runtime?

like image 767
GreenScape Avatar asked Sep 15 '14 09:09

GreenScape


1 Answers

The compiler may not know what CPU the code will run on, and CPUs may differ in their lock-free capabilities. For example, a CPU may not support atomic operations on long types (and so a lock may be needed), but if the system has only a single core, they may be atomic automatically because they can't be interrupted and there's no other core to race with (and so nothing special is needed and the type is lock free).

like image 186
David Schwartz Avatar answered Nov 08 '22 05:11

David Schwartz