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

Do I need to protect access to a Boost MultiIndex's index (the index itself) by a lock?

本文关键字:索引 MultiIndex 访问 Boost 是否 保护      更新时间:2023-10-16

假设我有一个提升::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()是一个静态强制转换操作,本质上是线程安全的。