Questions tagged «concurrent-vector»

1
在其他线程中迭代并发向量时调用concurrency :: concurrent_vector :: push_back是否安全并发?
在https://docs.microsoft.com/zh-cn/cpp/parallel/concrt/reference/concurrent-vector-class?view=vs-2019#push_back中,push_back,begin,end被描述为并发安全 但是下面的代码是断言的。可能是因为元素已添加但尚未初始化。 struct MyData { explicit MyData() { memset(arr, 0xA5, sizeof arr); } std::uint8_t arr[1024]; }; struct MyVec { concurrency::concurrent_vector<MyData> v; }; auto vector_pushback(MyVec &vec) -> void { vec.v.push_back(MyData{}); } auto vector_loop(MyVec &vec) -> void { MyData myData; for (auto it = vec.v.begin(); it != vec.v.end(); ++it) { auto res …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.