久久久久久久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)行排序)
主站蜘蛛池模板: 国产亚洲精品精品国产亚洲综合 | 天天人人精品 | 国产黄色av网站 | 亚洲一区导航 | 日本成人中文字幕在线观看 | 国产大毛片 | 成人性生交a做片 | 精品美女在线观看 | 日韩在线国产精品 | 精品一区二区在线观看 | 一级aaaaaa毛片免费同男同女 | 国产高清一区二区三区 | 国产三级一区二区三区 | 欧美精品在欧美一区二区少妇 | 国产精品日韩一区 | 亚洲永久 | 成人欧美一区二区三区在线播放 | 99re6在线 | 久久av一区二区三区 | 一区二区三区视频免费观看 | 久久久久亚洲精品 | 91五月婷蜜桃综合 | 超碰在线观看97 | 日韩高清一区 | 日本成人免费网站 | 成人三级视频 | 中文字幕亚洲一区二区三区 | 亚洲精品一区二区三区四区高清 | 二区av| 国产精品亚洲一区二区三区在线观看 | 日本 欧美 国产 | 久久久久无码国产精品一区 | 91av在线视频观看 | 久久亚洲一区二区三区四区 | 久久91精品久久久久久9鸭 | 一级片免费在线观看 | 性色综合 | 日韩午夜 | 国产精品久久久久久久一区探花 | 久久国产精品免费一区二区三区 | 日韩欧美一级精品久久 |