I'm using such configuration:

  • .NET framework 4.5
  • Windows Server 2008 R2
  • HP DL360p Gen8 (2 * Xeon E5-2640, x64)

I have such field somewhere in my program:

protected int HedgeVolume;

I access this field from several threads. I assume that as I have multi-processor system it's possible that this threads are executing on different processors.

What should I do to guarantee that any time I use this field the most recent value is "read"? And to make sure that when I "write" value it become available to all other threads immediately?

What should I do?

  • just leave field as is.
  • declare it volatile
  • use Interlocked class to access the field
  • use .NET 4.5 Volatile.Read, Volatile.Write methods to access the field
  • use lock

I only need simplest way to make my program work on this configuration I don't need my program to work on another computers or servers or operation systems. Also I want minimal latency so I'm looking for fastest solution that will always work on this standard configuration (multiprocessor intel x64, .net 4.5).

Edit
Report