I have a stl map with integer as key and a vector of class object as its value.
class foo {
// provides wrapper around std::queue for thread safety
private :
std::queue<>
}
std::map<unsigned int, std::vector<foo *> > mymap;
foo class is just a thread safe wrapper around std::queue implementation. Now coming to the actual question - this map is used in a multi threaded scenario where each thread depending upon an arguments passed during creation accesses the corresponding vector.
So lets say i created 4 threads and passed 0,1,2,3 as argument so :
thread 0 - mymap[0];
thread 1 - mymap[1];
thread 2 - mymap[2];
thread 3 - mymap[3];
- Size of the map is fixed during creation and is not changed.
Do i need to make my map thread safe ?
- as the size of map is fixed so that there will be no re-ordering of the map .
- each thread changes only its corresponding vector as per its id.