gpt4 book ai didi

c++ - 对 vector (vector::operator[] 和 vector::size())的只读访问是异步安全的吗?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:18:48 25 4
gpt4 key购买 nike

我的程序需要对 vector<string> 的内容执行只读访问在 SIGINT 的信号处理程序中. (另一种方法是使用固定长度的 C 字符串的固定大小数组。)该程序设计为在 POSIX 环境中运行。

vector::operator[]vector::size()异步安全(或信号安全)?

最佳答案

不,这不安全。 C++11 1.9/6:

When the processing of the abstract machine is interrupted by receipt of a signal, the values of objects which are neither

  • of type volatile std::sig_atomic_t nor
  • lock-free atomic objects (29.4)

are unspecified during the execution of the signal handler, and the value of any object not in either of these two categories that is modified by the handler becomes undefined.

关于c++ - 对 vector (vector::operator[] 和 vector::size())的只读访问是异步安全的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26242231/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com