Segfault in std::atomic load?

╄→尐↘猪︶ㄣ 提交于 2021-01-27 04:27:28

问题


On linux, using gcc 4.8.4, compiled with -std=c++11 -mcx16:

#include <atomic>

struct node_t;

struct pointer_t {
        node_t* ptr;
        unsigned int count;
        pointer_t() noexcept : ptr{nullptr}, count{0} {}
};

struct empty {};

struct node_t {
        empty value;
        std::atomic<pointer_t> next;
        node_t() : next{pointer_t{}} {}
};

int main() {
        node_t{}.next.load();
        return 0;
}

gives a segfault when load is called. How am I meant to initialize an atomic value?


回答1:


Turns out this is a bug in gcc that has since been fixed in GCC 5.1. Specifying the alignment to be two words fixed it.



来源:https://stackoverflow.com/questions/29824570/segfault-in-stdatomic-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!