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

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -