0

Is my impression correct that if shared memory between threads is only read and never written, by any of the threads, mutex protection is unneccessary?

It's because wherever a thread is preempted, it can always take off again when rescheduled, and the memory contents would not have changed.

Iceman
  • 4,202
  • 7
  • 26
  • 39

2 Answers2

4

Yes, you're right, multiple threads reading the same variable do not introduce a race.

Alex Telishev
  • 2,264
  • 13
  • 15
3

Both C++11 and C11 define a data race to be access to a memory location by more than one execution context without ordering where at least one of the accesses is a write. If you have no writes, you have no races.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084