《Advanced .NET Debugging》 读书笔记 Listing 6-3: 取得Lock的简单示例
时间:2011-01-09 来源:李志鹏
using System;
using System.Text;
using System.Threading;
namespace Advanced.NET.Debugging.Chapter6
{
class Simple
{
static void Main(string[] args)
{
Simple s = new Simple();
s.Run();
}
public void Run()
{
this.GetHashCode();
Console.WriteLine("Press any key to acquire lock");
Console.ReadLine();
Monitor.Enter(this);
Console.WriteLine("Press any key to release lock");
Console.ReadLine();
Monitor.Exit(this);
Console.WriteLine("Press any key to exit");
Console.ReadLine();
}
}
}
1. 使用WinDbg载入 06simple.exe
2. 执行 .loadby sos.dll mscorwks
3. 执行 ~0s切换到thread 0, 执行 !clrstack –a , 结果如下:
4. 执行 dd 0x0000000002493820-0x4 l1 结果如下:
这里08000001 实际上是0b00001000000000000000000000000001, 标志位置位表明这是一个syncblk,而1是这个syncblk的编号。