同时修改 std::valarray<T> 的元素是否安全?

Is it safe to modify elements of std::valarray<T> concurrently?

如果我没理解错的话,从 C++11 开始,可以安全地同时调用容器的 const 成员函数并修改容器的元素,只要容器本身不作为操作(从 cppreference.com 中关于线程安全的 table 可以看出)。由于 std::valarray 未列在(草案)标准的容器部分中,我不确定线程​​安全是否也适用于它。也就是说,

我想将 std::valarray 用于将使用多个线程填充的多维数字数组。

如果我没看错你的问题,[res.on.data.races] 保护 不同的切片 不参与

下的数据竞争

A C++ standard library function shall not directly or indirectly access objects accessible by threads other than the current thread unless the objects are accessed directly or indirectly via the function's arguments, including this.

[container.requirements.dataraces] 为不同元素的修改添加了额外的保护,严格来说 valarray 缺乏。