std::vector, thread-safety, multi-threading

后端 未结 3 1062
傲寒
傲寒 2020-11-27 08:21

I am using std::vector as shared data in a multi-threaded application. I encapsulate the thread inside a class, e.g.,

class ABC {
public:
    double a, b, c         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 08:36

    You call ptrVector->size() without locking it first. This could easily be the cause of your problems. Make sure to lock your vector before any reads or writes.

提交回复
热议问题