J
Jim
Hi all,
I have a question regarding the operation of critical sections within a
class definition. Below is an example class that contains two methods that
perform locks on the current instance. The methods themselves are not
tagged with the [MethodImlp(MethodImplOptions.Synchronized)] attribute. The
object is shared across multiple threads.
Are the critical sections in Method1() and Method2() mutually exclusive?
ie. If "Thread A" has acquired the lock and is executing within the
critical section of Method1(), will "Thread B" wait for the lock to be
released before it can execute the critical section in Method2()?
Thanks,
Jim
class A
{
public A {}
public void Method1 ()
{
lock (this)
{
...
}
}
public void Method2 ()
{
lock (this)
{
...
}
}
}
I have a question regarding the operation of critical sections within a
class definition. Below is an example class that contains two methods that
perform locks on the current instance. The methods themselves are not
tagged with the [MethodImlp(MethodImplOptions.Synchronized)] attribute. The
object is shared across multiple threads.
Are the critical sections in Method1() and Method2() mutually exclusive?
ie. If "Thread A" has acquired the lock and is executing within the
critical section of Method1(), will "Thread B" wait for the lock to be
released before it can execute the critical section in Method2()?
Thanks,
Jim
class A
{
public A {}
public void Method1 ()
{
lock (this)
{
...
}
}
public void Method2 ()
{
lock (this)
{
...
}
}
}