简体   繁体   English

在std :: atomic load中的Segfault?

[英]Segfault in std::atomic load?

On linux, using gcc 4.8.4, compiled with -std=c++11 -mcx16: 在linux上,使用gcc 4.8.4,使用-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. 在调用load时给出段错误。 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. 事实证明这是gcc中的一个错误 ,已经在GCC 5.1中得到修复。 Specifying the alignment to be two words fixed it. 指定对齐是两个单词修复它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 分配等效于std :: atomic的加载/存储<bool> - Is assignment equivalent to load/store for std::atomic<bool> std :: atomic :: load的内存排序行为 - Memory ordering behavior of std::atomic::load 的std ::原子 <int> - 原子加载并重置为0? - std::atomic<int> - load and reset to 0 atomically? 应该是std :: atomic <int*> :: load正在进行比较和交换循环? - Should std::atomic<int*>::load be doing a compare-and-swap loop? 原子的<T> .load() 与 std::memory_order_release - atomic<T>.load() with std::memory_order_release 在std :: atomic :: load的结果上使用Structure dereference( - &gt;)运算符是否安全 - Is it safe to use the Structure dereference(->) operator on the result of std::atomic::load std :: atomic变量应该使用“normal”语法还是“load”和“store”? - Should std::atomic variables use “normal” syntax or “load” and “store”? 使用std :: atomic中的方法时是否隐式调用load()? - Is load() called implicitly when using a method from an std::atomic? VC11中std :: shared_ptr上的atomic_load / atomic_store - 为什么是全局自旋锁? - atomic_load/atomic_store on std::shared_ptr in VC11 - why the global spinlock? 在具有相同顺序的原子加载/存储之前使用 std::atomic_thread_fence 总是多余的吗? - Is using std::atomic_thread_fence right before an atomic load/store with the same order always redundant?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM