Is locking or Interlocked.Exchange required to swap a reference type field which is used in an other thread?
0
I know that there are .NET collections which are thread safe which I could use, but I still want to understand the following situation: I have a Buffer class (below) which is used to writer data from a different thread, in a update loop interval (game) the main thread handles the data by swaping the list instance (to prevent both threads acting on the same instance at the same time). So there is only a single additional thread who uses the "writerData" list, everything else is done on the main thread, but im not sure if the Swap method is thread "safe", because after searching for a while everyone seems to have a different opinion about swapping reference fields. Some say that swapping reference doesn't require any locking other say that Interlocked.Exchange must be used in this case...