std :: atomic负载中的段错误? [英] Segfault in std::atomic load?

查看:160
本文介绍了std :: atomic负载中的段错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux上,使用gcc 4.8.4,使用-std = c ++ 11 -mcx16进行编译:

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;
}

在调用 load 时出现段错误.我要初始化一个原子值是什么意思?

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.

这篇关于std :: atomic负载中的段错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆