c# - How come this code does not deadlock? -


shouldn't log method block?

namespace sandbox { class program {     static void main(string[] args) {         var log = new logger();         lock (log) {             log.log("hello world!");         }     } }  public class logger {     public void log(string message) {         lock (this) {             console.writeline(message);         }     } } 

}

the same thread acquiring same lock twice. works because .net supports so-called recursive locks (aka reentrant mutexes).


Comments

Popular posts from this blog

WPF: binding viewmodel property of type DateTime to Calendar inside ItemsControl -

java - Getting corefrences with Standard corenlp package -

jQuery clickable div with working mailto link inside -