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

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -