TimedLock revisited

code 0 comments suggest edit

In an earlier blog entry, I asked the question if it made sense to add code in a debug version of the TimedLock class (written by Ian Griffiths in this post and commented on by Eric Gunnerson in this post) to store the stack trace when acquiring a lock on an object so that if another thread blocks an attempt to acquire a TimedLock, we can discover the StackTrace of the blocking thread.

Well I stopped asking questions and started writing answers. I update the TimedLock class with stack trace tracking and also wrote an NUnit test that demonstrates the fact that we can identify the stack trace. Check out the source code in the TimedLock repository.

Please keep in mind, this is meant to be a DEBUG version. In order to store the stack trace, I place it and the object being locked into a static hash table. In doing so, I acquire a lock on the hash table which can hinder overall concurrency as it is a static member. Hopefully, this will still be useful for tracking a pesky deadlock issue. I haven’t done any serious analysis or testing yet, so I welcome your comments if I’m way off base.

Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.



2 responses

  1. Avatar for nospamplease75@yahoo.com (Haac
    nospamplease75@yahoo.com (Haac April 20th, 2004

    Ian Griffiths found a few minor issues with my implementation. I'll try to fix them soon and post the changes. Just a bit of sloppiness on my part. I will lash myself twenty times for penance.

  2. Avatar for Ian Griffiths
    Ian Griffiths April 27th, 2004

    Trackback doesn't appear to be working, so I thought I'd better post manually... I've got an update on this article: