multithreading - C# \ Lock \ lock instance member VS lock static member -
what better? there difference in runtime between 2 options?
there no runtime difference between locking static , locking instance member. however, can break code if use instance lock , updating static.
class broken { static int mycounter; object synch = new object(); void somemethod() { lock (synch) { // bad ++mycounter; } } }
Comments
Post a Comment