21

Why doesn't

std::atomic<int> index;

Work?

Currently using LLVM 3.1 with these params

C Language Dialect GNU [-std=gnu99]
C++ Language Dialect [-std=c++11]
C++ Standard Library libc++(LLVM C++ standard library with C++11 support)
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Hobbyist
  • 885
  • 2
  • 10
  • 23

3 Answers3

15

There are several things that need to be true for your code to work:

  1. You need to #include <atomic>

  2. You need to compile the code as C++11 or C++14 (-std=c++11 or -std=c++14 (or c++0x for older compilers))

  3. Your compiler and standard library needs to support enough of C++11 to provide atomic (http://clang.llvm.org/cxx_status.html)

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70
3

Adding -std=c++11 to CXXFLAGS in my Makefile -> that works for me!

tamtam
  • 641
  • 9
  • 24
-6

You need to write it as the following to defined variable.

    std::atomic<std::int> index;