我有这个 C# 代码:
public class Locking
{
private int Value1; private int Value2;
private object lockValue = new Object();
public int GetInt1(int value1, int value2)
{
lock (lockValue)
{
Value1 = value1;
Value2 = value2;
return GetResult();
}
}
public int GetInt2(int value1, int value2)
{
lock (lockValue)
{
return GetInt1(value1, value2);
}
}
private int GetResult()
{
return Value1 + Value2;
}
}
所以基本上,如果我执行GetInt2
但代码只是执行,我预计会出现死锁。任何好的解释。