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

C++11 STL 容器和線程安全

C++11 STL containers and thread safety(C++11 STL 容器和線程安全)
本文介紹了C++11 STL 容器和線程安全的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我無法找到任何關于此的最新信息.

I have trouble finding any up-to-date information on this.

C++11 版本的 STL 容器是否有一定程度的線程安全保證?

Do C++11 versions of STL containers have some level of thread safety guaranteed?

由于性能原因,我確實希望它們不會.但話又說回來,這就是為什么我們有 std::vector::operator[]std::vector::at.

I do expect that they don't, due to performance reasons. But then again, that's why we have both std::vector::operator[] and std::vector::at.

推薦答案

由于現有的答案沒有涵蓋它(只有評論可以),我將僅提及 23.2.2 [container.requirements.dataraces]當前 C++ 標準規范 說:

Since the existing answers don't cover it (only a comment does), I'll just mention 23.2.2 [container.requirements.dataraces] of the current C++ standard specification which says:

當同時修改同一序列中不同元素中包含的對象的內容時(vector 除外),需要實現以避免數據競爭.

implementations are required to avoid data races when the contents of the contained object in different elements in the same sequence, excepting vector<bool>, are modified concurrently.

即訪問同一容器的不同元素是安全的,例如,您可以擁有一個包含十個元素的全局 std::vector<std::future 并且有十個線程,每個線程都寫入到向量的不同元素.

i.e. it's safe to access distinct elements of the same container, so for example you can have a global std::vector<std::future<int>> of ten elements and have ten threads which each write to a different element of the vector.

除此之外,容器的規則與標準庫的其余部分相同(參見 17.6.5.9 [res.on.data.races]),如 C64 先生的回答 說,另外 [container.requirements.dataraces] 列出了一些可以安全調用的容器的非常量成員函數,因為它們只返回非常量引用元素,它們實際上并沒有修改任何東西(通常任何非常量成員函數都必須被視為修改.)

Apart from that, the same rules apply to containers as for the rest of the standard library (see 17.6.5.9 [res.on.data.races]), as Mr.C64's answer says, and additionally [container.requirements.dataraces] lists some non-const member functions of containers that can be called safely because they only return non-const references to elements, they don't actually modify anything (in general any non-const member function must be considered a modification.)

這篇關于C++11 STL 容器和線程安全的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 排序功能對列表進行排序)
主站蜘蛛池模板: 九色在线播放 | 深夜福利网址 | 成人网av | 亚洲欧美一区二区三区在线 | 天天操天天干天天 | 黄色一级录像 | 超碰精品在线 | 91靠逼视频 | 国产免费av在线 | 国产精品久久久久久久 | 欧美性生交xxxxx | 国产又粗又长又爽 | 国产三级在线看 | 黄色成人在线 | 国产伦理一区二区 | 手机在线免费看av | 久插视频| 国产a视频 | 三级在线看 | 国产特黄 | 欧美成人三级 | 成人综合网站 | 我要看一级黄色片 | 欧美1级片 | 在线免费看毛片 | www.av在线播放| 日韩毛片免费 | 久久老司机 | 亚洲伦理在线观看 | 欧美日韩黄 | 日韩欧美久久 | 91亚洲精品乱码久久久久久蜜桃 | 天海翼在线视频 | 国产精品免费一区二区三区 | 亚洲欧美视频在线观看 | 嫩草国产 | 超碰97久久| 国产精品久久久久久精 | 国产一区二区福利 | 又黄又爽又色视频 | 日韩在线毛片 |