Are find and read operations on std::map threadsaf

2019-07-22 08:49发布

问题:

Possible Duplicate:
Thread safety of std::map for read-only operations

Having std::map a can we do a.find(...)->second in multiple threads at the same time on it?

回答1:

Yes. As long as none of your threads do a write

i.e. Construct the data structure in memory

Use as many threads to find/read as you require.

If the leaf needs altering put a mutex there.