How to correctly use std::atomic_signal_fence()?

后端 未结 2 1959
情歌与酒
情歌与酒 2021-02-04 09:57

cppreference.com documents this function as \"fence between a thread and a signal handler executed in the same thread\". But I found no example on the Internet.

I wonder

2条回答
  •  醉话见心
    2021-02-04 10:48

    In your example, you want to use std::atomic_thread_fence (which generates machine code to perform thread synchronization); not std::atomic_signal_fence (which only disables compiler memory reordering optimizations on atomic variables). As was said by others, std::atomic_signal_fence is only intended for signals on the same thread as the atomic operations (I believe it would also hold true for structured/vectored exception handlers on Windows, but don't quote me on that).

提交回复
热议问题