1

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?

Community
  • 1
  • 1
Rella
  • 65,003
  • 109
  • 363
  • 636

1 Answers1

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.

Ed Heal
  • 59,252
  • 17
  • 87
  • 127
  • Better still, if your OS supports it, use a read-write lock instead of just a mutex. Multiple readers, single writer, beautiful. – Adam Hawes Aug 26 '11 at 00:49