杜佩內:return statement in a lock procedure: inside or outside我可以把一個return語句鎖
標題是有點誤導。我知道你可以做到,但我想知道性能影響。
考慮這兩個代碼塊。 (沒有錯誤處理)
此塊具有return
外鎖
public DownloadFile Dequeue()
{
DownloadFile toReturn = null;
lock (QueueModifierLockObject)
{
toReturn = queue[0];
queue.RemoveAt(0);
}
return toReturn;
}
此塊具有return
聲明內鎖
public DownloadFile Dequeue()
{
lock (QueueModifierLockObject)
{
DownloadFile toReturn = queue[0];
queue.RemoveAt(0);
return toReturn;
}
}
的有代碼中的任何差異?我明白性能差異(如果有的話)會很小,但我特別想知道lock
獲得發佈的順序是否會有所不同。
*當然*這已被覆蓋之前? – annakata 2009-08-31 20:22:14
我找不到結果,因爲我之前沒有使用正確的搜索字詞。是的,這是一個騙局。 – DevinB 2009-08-31 20:38:38