简体   繁体   English

Boost的无序容器是否对读取线程安全?

[英]Are Boost's unordered containers Thread-safe for reading?

For example, for MSVC, read-only is thread-safe on containers . 例如,对于MSVC, 只读对container是线程安全的

Is boost similarly thread-safe for read-only? boost对于只读是否同样具有线程安全性?

Update: ie Can we expect `const' methods to guarantee no memory corruption for multi-threaded use. 更新:即我们可以期望const方法来保证多线程使用不会造成内存损坏吗?

Typically read operations are thread-safe. 通常,读取操作是线程安全的。 I would expect any class implementing a read-only operation (or more generally, a const function) to explicitly call out the fact that is is not thread safe. 我希望实现一个只读操作的任何类(或更一般地,一个const函数)来显式调用出来的事实,是不是线程安全的。

That said, I don't see any thread safety guarantees anywhere. 也就是说,我在任何地方都看不到任何线程安全保证。

The upcoming standard defines the thread safety of all standard containers, and I would be very surprised if the boost implementations didn't meet this guarantee. 即将到来的标准定义了所有标准容器的线程安全性,如果boost实现不符合此保证,我将感到非常惊讶。 In particular, you should be able to read from any instance of the container from any thread, as long as no thread is modifying the container. 特别是,只要没有线程在修改容器,就应该能够从任何线程读取容器的任何实例。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM