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

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

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

問題描述

我無法找到任何關(guān)于此的最新信息.

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?

由于性能原因,我確實(shí)希望它們不會.但話又說回來,這就是為什么我們有 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.

推薦答案

由于現(xiàn)有的答案沒有涵蓋它(只有評論可以),我將僅提及 23.2.2 [container.requirements.dataraces]當(dāng)前 C++ 標(biāo)準(zhǔn)規(guī)范 說:

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:

當(dāng)同時修改同一序列中不同元素中包含的對象的內(nèi)容時(vector 除外),需要實(shí)現(xiàn)以避免數(shù)據(jù)競爭.

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.

除此之外,容器的規(guī)則與標(biāo)準(zhǔn)庫的其余部分相同(參見 17.6.5.9 [res.on.data.races]),如 C64 先生的回答 說,另外 [container.requirements.dataraces] 列出了一些可以安全調(diào)用的容器的非常量成員函數(shù),因?yàn)樗鼈冎环祷胤浅A恳迷?,它們?shí)際上并沒有修改任何東西(通常任何非常量成員函數(shù)都必須被視為修改.)

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.)

這篇關(guān)于C++11 STL 容器和線程安全的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

What is the fastest way to transpose a matrix in C++?(在 C++ 中轉(zhuǎn)置矩陣的最快方法是什么?)
Sorting zipped (locked) containers in C++ using boost or the STL(使用 boost 或 STL 在 C++ 中對壓縮(鎖定)容器進(jìn)行排序)
Rotating a point about another point (2D)(圍繞另一個點(diǎn)旋轉(zhuǎn)一個點(diǎn) (2D))
Image Processing: Algorithm Improvement for #39;Coca-Cola Can#39; Recognition(圖像處理:Coca-Cola Can 識別的算法改進(jìn))
How do I construct an ISO 8601 datetime in C++?(如何在 C++ 中構(gòu)建 ISO 8601 日期時間?)
Sort list using STL sort function(使用 STL 排序功能對列表進(jìn)行排序)
主站蜘蛛池模板: 成年免费大片黄在线观看岛国 | 二区国产 | 欧美黄页| 日韩高清不卡 | 久久一本 | 永久www成人看片 | 91看片免费版 | 91毛片在线看 | 婷婷福利视频导航 | 一区二区福利视频 | 在线观看国产www | 久色一区 | 在线欧美亚洲 | 免费在线观看成人 | 日韩一区二区免费视频 | 国产98色在线 | 日韩 | 一区二区三区四区日韩 | 免费一区在线观看 | 亚洲国产精品久久久 | 日韩欧美国产一区二区三区 | 久久大陆 | 97超碰人人| 成人精品久久 | 亚洲视频一区二区三区 | 国产 欧美 日韩 一区 | 天天射视频 | 欧美成人a | 久久精品成人热国产成 | 亚洲欧美日韩成人在线 | 爱草视频 | 久久精品久久久久久 | 国产一区免费视频 | 亚洲成人精品 | 久久久精品国产 | 91精品国产综合久久久久久丝袜 | 久久精品国产久精国产 | 91精品国模一区二区三区 | 99久久婷婷国产综合精品 | 91精品久久久久久久久99蜜臂 | 日韩在线不卡 | 欧美视频区 |