In the code that you posted, no, the second lock does not add any value, as it is not possible to get to that code without executing the while loop first, at which point the mutex will already have been locked.
It is probably important to note that it doesn't hurt to have it in there, though, as C# locks are reentrant.
Where the second lock does add value is in code where it is not clear that the first lock will always be obtained. For example:
void DoWork1()
{
lock(_queues)
{
//do stuff...
if(condition)
DoWork2();
}
}
void DoWork2()
{
lock(_queues)
{
//do stuff...
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…