Catching exceptions and locks

Locks and exceptions do not mix <Eric Lippert’s Blog>

In summary, you want to

  1. Do as little as possible in the body of a lock.
  2. Even though it’s difficult and for many cases next to impossible, return your application to a pristine state. i.e.  “carefully implement the bodies of locks that do mutations so that in the event of an exception, the mutated resource is rolled back to a pristine state before the lock is released.”
  3. Don’t abort threads for the reason of leaving you application in an inconsistent state (unrecoverable). The thread should wait for a synch object and then return from the running methods in a consistent manner.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s