All Projects → haacked → TimedLock

haacked / TimedLock

Licence: MIT license
A Lock structure with timeout and stack traces in case of deadlock

Programming Languages

C#
18002 projects

TimedLock

A Lock structure with timeout and stack traces in case of deadlock

Here's the original blog post that introduces the concept from Ian Griffiths.

I wrote a series of blog posts trying to improve on this.

I finally moved the code into this Repository.

Usage Example

try
{
    TimedLock timeLock = TimedLock.Lock(obj);
    //Thread safe operations
    timeLock.Dispose();
}
catch(LockTimeoutException e)
{
    Console.WriteLine("Couldn't get a lock!");
    StackTrace otherStack = e.GetBlockingThreadStackTrace(5000);
    if(otherStack == null)
    {
        Console.WriteLine("Couldn't get other stack!");
    }
    else
    {
        Console.WriteLine("Stack trace of thread that owns lock!");
    }
}

Note, you'll only ever get the other stack trace in DEBUG builds.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].