Ok, so Valgrind/Helgrind is having issues with my program. Says I have an unreasonable number data race conditions.
My code is something like this.
vector<CatObj> catobj;
Each CatObj contains
vector<CatObj*> catobj_ptrvec[3];
So every object in catobj contains a native static array of 3 vectors of pointers to CatObj. These catobj_ptrvec will be populated with pointers to objects in the catobj vector.
Head hurt yet?
So here's where the threading bit & the claimed data-race comes in. Each of the three catobj_ptrvec is populated by the same algorithm - so I kick this algorithm off in three separate threads, each thread takes a different index (0, 1, 2) and works on a different element of catobj_ptrvec
So you could have this function, in separate threads, simultaneously doing this:
Thread 1 - catobj[100].catobj_ptrvec[0].push_back(&(catobj[200]));
Thread 2 - catobj[100].catobj_ptrvec[1].push_back(&(catobj[200]));
Thread 3 - catobj[100].catobj_ptrvec[2].push_back(&(catobj[200]));
As far as I can tell, this should be OK. While all three threads are writing to the same catobj_ptrvec, they are all writing to different elements of this native vector, so it should be kosher. Right? Apparently Valgrind doesn't think so.
If anybody has followed this, any insight is appreciated?!
My code is something like this.
vector<CatObj> catobj;
Each CatObj contains
vector<CatObj*> catobj_ptrvec[3];
So every object in catobj contains a native static array of 3 vectors of pointers to CatObj. These catobj_ptrvec will be populated with pointers to objects in the catobj vector.
Head hurt yet?
So here's where the threading bit & the claimed data-race comes in. Each of the three catobj_ptrvec is populated by the same algorithm - so I kick this algorithm off in three separate threads, each thread takes a different index (0, 1, 2) and works on a different element of catobj_ptrvec
So you could have this function, in separate threads, simultaneously doing this:
Thread 1 - catobj[100].catobj_ptrvec[0].push_back(&(catobj[200]));
Thread 2 - catobj[100].catobj_ptrvec[1].push_back(&(catobj[200]));
Thread 3 - catobj[100].catobj_ptrvec[2].push_back(&(catobj[200]));
As far as I can tell, this should be OK. While all three threads are writing to the same catobj_ptrvec, they are all writing to different elements of this native vector, so it should be kosher. Right? Apparently Valgrind doesn't think so.
If anybody has followed this, any insight is appreciated?!