lock() <-> exception question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rainer Queck

    lock() <-> exception question

    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


  • Marc Gravell

    #2
    Re: lock() &lt;-&gt; exception question

    no. The lock() construct is analogous to

    Monitor.Enter(l ockObj);
    try {
    // code
    } finally {
    Monitor.Exit(lo ckObj)
    }

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

    Marc


    Comment

    • Rainer Queck

      #3
      Re: lock() &lt;-&gt; exception question

      Thanks for the info.

      Rainer

      "Marc Gravell" <marc.gravell@g mail.comschrieb im Newsbeitrag
      news:OSoRx9z$GH A.3604@TK2MSFTN GP04.phx.gbl...
      no. The lock() construct is analogous to
      >
      Monitor.Enter(l ockObj);
      try {
      // code
      } finally {
      Monitor.Exit(lo ckObj)
      }
      >
      The lock is released when leaving the critical section, regardless of
      whether it is success or an exception.
      >
      Marc
      >

      Comment

      Working...