I'm trying to parallelize a simulation model using TThreads. The model objects each include amongst other things a std::map<obj*, int>
. The model runs fine as long only one thread is running. If a second thread starts, I get an access violation in the map of the model of the first thread.
To test if the map is really the problem, I replaced it with a std::vector<pair<obj*, int> >
. This works fine, but is much slower since I have to iterate through the entire Vector every time I try to find a specific obj*
.
I know there is no possibility to reserve memory for a map, therefore I don't know how to work with the map without access violations.