久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

boost shared_mutex 的示例(多次讀取/一次寫入)?

Example for boost shared_mutex (multiple reads/one write)?(boost shared_mutex 的示例(多次讀取/一次寫入)?)
本文介紹了boost shared_mutex 的示例(多次讀取/一次寫入)?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個多線程應用程序,它必須經常讀取一些數據,并且偶爾會更新這些數據.現在互斥鎖可以安全地訪問該數據,但它很昂貴,因為我希望多個線程能夠同時讀取,并且僅在需要更新時將它們鎖定(更新線程可以等待其他線程完成).

I have a multithreaded app that has to read some data often, and occasionally that data is updated. Right now a mutex keeps access to that data safe, but it's expensive because I would like multiple threads to be able to read simultaneously, and only lock them out when an update is needed (the updating thread could wait for the other threads to finish).

我認為這是 boost::shared_mutex 應該做的,但我不清楚如何使用它,也沒有找到一個明確的例子.

I think this is what boost::shared_mutex is supposed to do, but I'm not clear on how to use it, and haven't found a clear example.

有沒有人有一個簡單的例子可以讓我開始使用?

Does anyone have a simple example I could use to get started?

推薦答案

看起來你會這樣做:

boost::shared_mutex _access;
void reader()
{
  // get shared access
  boost::shared_lock<boost::shared_mutex> lock(_access);

  // now we have shared access
}

void writer()
{
  // get upgradable access
  boost::upgrade_lock<boost::shared_mutex> lock(_access);

  // get exclusive access
  boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
  // now we have exclusive access
}

這篇關于boost shared_mutex 的示例(多次讀取/一次寫入)?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

What is the fastest way to transpose a matrix in C++?(在 C++ 中轉置矩陣的最快方法是什么?)
Sorting zipped (locked) containers in C++ using boost or the STL(使用 boost 或 STL 在 C++ 中對壓縮(鎖定)容器進行排序)
Rotating a point about another point (2D)(圍繞另一個點旋轉一個點 (2D))
Image Processing: Algorithm Improvement for #39;Coca-Cola Can#39; Recognition(圖像處理:Coca-Cola Can 識別的算法改進)
How do I construct an ISO 8601 datetime in C++?(如何在 C++ 中構建 ISO 8601 日期時間?)
Sort list using STL sort function(使用 STL 排序功能對列表進行排序)
主站蜘蛛池模板: 日韩高清在线播放 | 亚洲精品第一 | 亚洲免费精品 | 91av免费在线观看 | 日韩福利视频 | aaa国产精品 | 波多野结衣视频一区 | 日韩毛片免费看 | 欧美日韩亚洲一区二区 | 亚洲精品www久久久久久广东 | 久久亚洲精品视频 | 99精品99 | 91片黄在线观看动漫 | 九九国产 | 99精品成人 | 日韩黄色在线 | 狠狠干狠狠干 | 日本一级大毛片a一 | 一区二区三区免费观看 | 亚洲国产精品久久久久 | 欧美黄色录像 | av免费观看网址 | 国产一区二三区 | 国产精品成人国产乱一区 | 色婷婷丁香 | 日韩手机看片 | 99热国产在线 | 国产精品成人一区二区三区 | 中文字幕精品在线观看 | 国产精品成人网 | 成年人一级片 | 国产日韩欧美在线 | 亚洲黄色片| 日本欧美久久久久免费播放网 | 吃奶动态图 | 亚洲免费在线观看视频 | 五月婷婷在线播放 | 最新日韩在线 | 日日干狠狠干 | www.久久精品 | 久久久www成人免费精品 |