Skip to content

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

License

Notifications You must be signed in to change notification settings

haacked/TimedLock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages