lock() <-> exception question

  • Thread starter Thread starter Rainer Queck
  • Start date Start date
R

Rainer Queck

Hi NG,

what happens if a exception in a lock block occures?

lock(myObject)
{
dothis();
dothat();
}

lets assume, dothis() causes a exception, does this mean, I get a deadlock?

Regards
Rainer
 
no. The lock() construct is analogous to

Monitor.Enter(lockObj);
try {
// code
} finally {
Monitor.Exit(lockObj)
}

The lock is released when leaving the critical section, regardless of
whether it is success or an exception.

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top