不應該日誌方法塊?這段代碼怎麼沒有死鎖?
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);
}
}
}
}
可能重複的[鎖定aqcuired和進一步嘗試鎖定不會阻止:是C#鎖再入?](http://stackoverflow.com/questions/4846010/lock-aqcuired-and-further-attempts-to -lock-do-not-block-are-c-locks-re-entrant) – 2011-02-18 20:06:28