STL map

I have written a multi threaded code. Where I am reading values into a map and then reading it just after that.

Its running absolutely fine but in some cases, its not giving the value I have written into it.

Here is the code snippet

1
2
3
map<int, int> log;
log[key] = key;
assert(log[key] == key);


this assertion is failing in some cases.

I have not changed this log anywhere else. So, I don't understand what is the problem. Is it possible that stl map is not working properly??

closed account (S6k9GNh0)
http://www.cprogramming.com/tutorial/stl/stlmap.html
Didn't get much info in the above link.. :(.

Can someone tell me if STL map supports multithreading. I haven't used lock while many threads trying to add items into the map. Can that be a problem??

HUH....

This is really confusing... some people say STL:map is thread safe and some says its not... :(

Whats actually the answer?
STL is not thread safe. But mostly you can avoid race conditions as there is no static data in STL. But otherwise you need to synchronize your code if you have many threads.
Thanks for the help.. :)
Nothing in STL is threadsafe for any number of threads. You are lucky the above code doesn't just seg fault.
Yes, you will need to use mutexes or locks in order to prevent multiple threads from accessing the data at the same time.
Topic archived. No new replies allowed.