c++ - 我是否需要通过锁来保护对 Boost MultiIndex 索引(索引本身)的访问?

标签 c++ boost locking multi-index

假设我有一个 boost::multi_index_container 并想访问它的索引

  boost::multi_index_container< ... > bmi;
  // lock here?
  auto &index = boost::multi_index::get<0>(bmi);   // <-- does this call need to be protected by a lock?

  // or is it sufficient to lock here?

  // access the index (need to have the lock here)

当多个进程/线程访问一个 multi_indesx_container 时,我需要使用互斥锁(或类似的东西)。但是我是否也需要保护获取索引本身? 我猜不是,但无法在文档中找到保证。

最佳答案

虽然没有在任何地方记录,get() 是一个 static cast operation ,本质上是线程安全的。

关于c++ - 我是否需要通过锁来保护对 Boost MultiIndex 索引(索引本身)的访问?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53982289/

相关文章:

c++ - 在 C++17 中 i++ + i++ 会评估什么?

c++ - Basler Pylon 4 SDK 和 OPENCV 2.4.9,CPylonImage 到 Mat

c++ - 在 boost::spirit::x3 中合成 std​​::pair 属性

c++ - 使用 boost::regex 更改文件中数据的格式

c# - 使用 `lock` 比 `SemaphoreSlim` 有什么优势?

c# - 锁定创建 ID 的对象

c++ - header 中的字符串——这是否违反了 ODR?

c++ - 显示 MessageBox 时暂停父窗口操作

c++ - 在 darwin 上静态 boost 包括 libstdc++?

jpa - 用于应用程序同步的数据库锁