Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is_lock_free not defined in std::atomic<T> in gcc 4.7.2?

I encounter this compiler error

function std::atomic::is_lock_free() const: error: undefined reference 
to '__atomic_is_lock_free' 

when compiling code like below using gcc 4.7.2 on linux.

struct S {
  int a;
  int b;
};


  std::atomic<S> s;
  cout << s.is_lock_free() << endl;
like image 500
Derek Avatar asked Mar 04 '13 14:03

Derek


1 Answers

Atomic API isn't complete in GCC 4.7:

  • When lock free instructions are not available (either through hardware or OS support) atomic operations are left as function calls to be resolved by a library. Due to time constraints and an API which is not finalized, there is no libatomic supplied with GCC 4.7. This is easily determined by encountering unsatisfied external symbols beginning with __atomic_*.

Since there is no libatomic shipped with GCC 4.7 you need to use another compiler which actually supports the features you want or provide the missing features (sample implementation).

like image 117
Zeta Avatar answered Nov 15 '22 12:11

Zeta