不确定性问题,考考你,一个很简单却很多人都不确定的问题

A:
void Test(int i)
{
while(i>0)
{
lock(this)
{
i--;
Test(i);
}
}
}
会死锁不?
或者,B:
void Test(int i)
{
while(i>0)
{
lock(this)
{
i--;
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(delegate(object obj) { int ii=(int)obj;
Test(ii);
}));
thread.Start(i);
}
}
}
会死锁不?
再或者,C:
void Test(int i)
{
while(i>0)
{
lock(this)
{
i--;
lock(this.GetType())
{ System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(delegate(object obj) { int ii=(int)obj;
Test(ii);
}));
thread.Start(i);
}
}
}
}
会死锁不?
Tags: 

延伸阅读

最新评论

发表评论