How to use Multiple Variables for a lock Scope in C#
Posted
by Gunner
on Stack Overflow
See other posts from Stack Overflow
or by Gunner
Published on 2010-05-20T13:17:03Z
Indexed on
2010/05/20
13:20 UTC
Read the original article
Hit count: 230
I have a situation where a block of code should be executed only if two locker objects are free.
I was hoping there would be something like:
lock(a,b)
{
// this scope is in critical region
}
However, there seems to be nothing like that. So does it mean the only way for doing this is:
lock(a)
{
lock(b)
{
// this scope is in critical region
}
}
Will this even work as expected? Although the code compiles, but I am not sure whether it would achieve what I am expecting it to.
© Stack Overflow or respective owner