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

标签 c++ vector posix signal-handling async-safe

我的程序需要对 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/

相关文章:

c++ - C++ 中的 vector <int>::size_type

linux - 如何在不同的 shellscsh/tcsh shell 上执行 sh shell 脚本?

c++ - 这是正确的 : virtual method of Derived called before constructing Base object?

以函数指针作为参数的 C++ 外部函数,在具有成员函数的类内部使用

c++ - 如何更改 C++ STL vector 的特定元素

调用信号处理程序但仍然忽略信号 (Posix, C)

c++ - 使用互斥量时出错

c++ - 无需测试即可更改循环内部

c++ - 虚函数

Python:区分行向量和列向量