简体   繁体   中英

Segfault in std::atomic load?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM