mardi 26 décembre 2017

std::atomic on a simple POD class

I have read many articles and questions on that, such as this, this, and this, and all the answers provided are inconclusive as to what should actually be done in such a situation:

Currently I am writing a concurrent program where I need to concurrently access the size and top of a std::priority_queue<std::pair<int, int>> many times, while pushing and popping elements elsewhere.
But it would be too inefficient to lock the mutex every time a read is needed (and a solution to readers and writers problem is not efficient enough either).

The only thing that is good enough is to wrap those three attributes in a std::atomic and update the atomic on every update of the queue, which would work, if only the compiler allowed me to do that.

Sadly, g++ 7.2.0 outputs the

"undefined reference to '__atomic_load'"

error message while linking.

I tried adding -latomic to the CMakeLists.txt, but I got

"/usr/bin/ld: cannot find -latomic"

error instead (and I am not allowed to change or update the compiler).

My struct is a POD type (I checked that with static_assert), so I just don't get why does it not work. How can I get it to work?

Aucun commentaire:

Enregistrer un commentaire