I would like to communicate some Informations between threads. Atomics sound like the thing to use. I had a look at this. And found that a simple struct like
struct MyType{
int val_a,val_b;
float vals_c[5];
};
should fullfill the assert:
static_assert(
std::is_trivially_copyable<MyType>::value &&
std::is_copy_constructible<MyType>::value &&
std::is_move_constructible<MyType>::value &&
std::is_copy_assignable<MyType>::value &&
std::is_move_assignable<MyType>::value,
"MyType is not suitable for std::atomic");
)
But a simple program as
//... MyType and static_assert
int main(int argc,char *argv[]){
MyType a;
std::atomic<MyType> b;
b = a;
a = b;
return 0;
}
fails to compile with:
undefined reference to `__atomic_store'
undefined reference to `__atomic_load'
I am using gcc version 5.4 on a 64-bit ubuntu 16.04.
Flags used are: -pipe -g -std=gnu++11 -Wall -W -fPIC
Is it that this is a total wrong use of std::atomic? What are the requirements to MyType? Or is just something missing from this setup?
Aucun commentaire:
Enregistrer un commentaire