1

In C, I am utilizing pthreads in order to perform computations on a shared array across pthreads. Each of the pthreads is distinctly given offsets so that their area of computation has no overlap.

Example:

  • Thread 0 updates array[0] thru array[9]
  • Thread 1 updates array[10] thru array[19]
  • Thread 2 updates array[20] thru array[29]

Are mutex locks still necessary in this case if none of the computation overlaps and they are not reliant on the updates of neighboring indices across thread boundaries?

Nick
  • 81
  • 5

1 Answers1

4

No, since these accesses are on separate, distinct memory locations, they are not even potentially conflicting, and so they do not require synchronization with respect to one another.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
  • 1
    As long as these are simple arrays. If he's using some fancy vector structure where accessing any element requires accessing(and potentially changing) the vector object itself, things might be more complicated. – Lee Daniel Crocker Apr 10 '17 at 19:45