TimedLock Yet Again Revisited...

lock In an earlier post, I updated the TimedLock class (first introduced in this post) to allow the user to examine the stack trace of the thread that is holding the lock to an object when the TimedLock fails to obtain a lock on that object. This assumes that the blocking lock was obtained using the TimedLock. Ian Griffiths pointed out a few flaws in my implementation and I promised I would incorporate his feedback and revise the code.

Since that time, Ian revisited the TimedLock based on comments he recevied and changed it to be a struct in both Debug and Release versions. He adds a new Sentinel class in the debug version. The finalizer in the Sentinal is used to detect whether or not the user of the TimedLock remembered to call Dispose. I've incorporated his new changes as well as his comments and have released my newest TimedLock struct. Download the code here. I have yet to update the NUnit tests (I know, bad programmer! Bad!).

As Ian points out, there are non-trivial costs involved in keeping track of the stack trace of every lock just in case we wish to examine it later. When I have some non-trivial free time, I'd like to examine other possibilities.

Technorati Tags: ,

What others have said

Requesting Gravatar... you've been HAACKED Aug 06, 2004 10:21 AM
# TimedLock Success Story!
Requesting Gravatar... Dimitri Glazkov Aug 06, 2004 2:55 PM
# Coding For Multithreading
Requesting Gravatar... Dimitri Glazkov Aug 06, 2004 3:07 PM
# Coding For Multithreading
Requesting Gravatar... you've been HAACKED Aug 25, 2004 10:35 AM
# TimedLock Success Story!
Requesting Gravatar... new TechBlog(); Oct 13, 2004 12:41 PM
# Multithreading is hard.
<p>Discovery of a race condition in the TimedLock class (from Ian Griffiths and Phil Haack), and other ruminations on multithreading.</p>
Requesting Gravatar... you've been HAACKED Oct 13, 2004 1:19 PM
# TimedLock with Stack Traces Strikes Back
Requesting Gravatar... you've been HAACKED Oct 13, 2004 3:37 PM
# TimedLock with Stack Traces Strikes Back
Requesting Gravatar... Pingback/TrackBack Sep 08, 2006 6:03 AM
# Useful IDisposable Class 1: TimedLock (Post 3 of 5) by sengelha () | LjSEEK.COM
Useful IDisposable Class 1: TimedLock (Post 3 of 5) by sengelha () | LjSEEK.COM
Requesting Gravatar... Mike Oct 03, 2006 5:27 PM
# good day
Anti-Anxiety Aromatherapy: blend 3 drops neroli,2 drops patchouli,2 drops geranium,2 drops rose,2 drops ylang-ylang,1 drop frankincense,1 drop bergamot

What do you have to say?

(will show your gravatar)
Please add 6 and 8 and type the answer here: