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
  • 62,177
  • 103
  • 350
  • 621

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
  • 57,599
  • 16
  • 82
  • 120
  • 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