相关疑难解决方法(0)

如何使用boost可升级互斥锁的示例

我有一个多线程服务器应用程序,需要在某些共享内存上进行互斥锁定.

共享内存基本上是sTL地图等.

很多时候我只是从地图上读书.但是,我还需要偶尔添加它.

例如typedef std :: map MessageMap; MessageMap msgmap; boost:shared_mutex access_;

void ProcessMessage(Message* message)
{
  //  Access message... read some stuff from it  message->...

  UUID id = message->GetSessionID();

  // Need to obtain a lock here. (shared lock? multiple readers)
  // How is that done?
  boost::interprocess::scoped_lock(access_);

  // Do some readonly stuff with msgmap
  MessageMap::iterator it = msgmap.find();
  // 

  // Do some stuff...

  // Ok, after all that I decide that I need to add an entry to the map.
  // …
Run Code Online (Sandbox Code Playgroud)

c++ boost-thread boost-interprocess

7
推荐指数
2
解决办法
1万
查看次数

标签 统计

boost-interprocess ×1

boost-thread ×1

c++ ×1