What is the best way to access an integer value from multiple threads?

117 Views Asked by At

I'm confused about how to choose the most effective way to synchronize multi threads. Supposed we have an integer value i to synchronize.

  1. 1-Write/1-Read : just simply ignore it or add volatile before i?
  2. 1-Write/N-Read : just simply ignore it or add volatile before i?
  3. N-Write/1-Read : Interlocked is the best way.
  4. N-Write/1-Read : Interlocked is the best way.

Should i use volatile, Interlocked or lock?

0

There are 0 best solutions below