Relative Content

Tag Archive for c#.netmultithreading

Why thread safety is listed as a benefit of immutability?

I was reading about Records in C# and read that they are immutable. And thread safety is written as a benefit of immutability. How immutability provides thread safety. I tried a code sample claiming to provide predictable results by using Records because they are immutable rather than using shared mutable object. I tried the code and the results were unpredictable: