I have a C# class with a static member, that is read from multiple threads and written in one thread.
As far as I know Uint64 read and write is not an atomic operation on all systems, so I have to manually guarantee thread safety.
I had a few ideas about how to do this.
Do it with and atomic wrapper class, like std::atomic in c++. Is there something similar implemented in C#?
Use the volatile modifier with static field. However this is not allowed. Why?
I finally did the following:
private static object tick_time_lock; private static UInt64 _currentTickTime; public static UInt64 CurrentTickTime { get { return _currentTickTime; } set { lock (tick_time_lock) { _currentTickTime = value; } } }
Is this the correct way of making this field thread-safe?
Interlockedutility class. - millimoose