1

Do we need any synchronization, if multiple threads access

pair<iterator,iterator> equal_range (const value_type& val) const;

Since equal_range is a read operation, it may not be required. Please comment.

juanchopanza
  • 216,937
  • 30
  • 383
  • 461
user2586432
  • 249
  • 1
  • 4
  • 12

1 Answers1

2

Like you said, since you are only "reading data" you don't need any synchronization, you can expect the function to be "thread-safe", see this question where the accepted answer states:

[17.6.5.9/3] A C++ standard library function shall not directly or indirectly modify objects (1.10) accessible by threads other than the current thread unless the objects are accessed directly or indirectly via the function’s non-const arguments, including this.

Community
  • 1
  • 1
Étienne
  • 4,406
  • 2
  • 31
  • 54
  • Huh? Since when does "only reading data" imply thread safety? Const does not guarantee that things don't change internally. For example it could cache a value internally. – tenfour Jun 14 '14 at 09:46
  • @tenfour You are right in the general case, but not in the context of this question. const actually guarantee that things don't change internally in the case of the standard library: http://stackoverflow.com/questions/14127379/does-const-mean-thread-safe-in-c11/14127380#14127380 – Étienne Jun 14 '14 at 10:07
  • 1
    Very interesting! I did not know this. – tenfour Jun 14 '14 at 10:15