What happens if a thread acquires a lock gets terminated before it releases the lock?

deleyd
deleyd used Ask the Experts™
on
What happens if a thread acquires a lock (SemaphoreSlim), and then that thread gets terminated before it releases the lock?

e.g.
private SemaphoreSlim semaphoreSlim = new SemaphoreSlim(1, 1);
public async Task DoStuff()
{
    using (semaphoreSlim.WaitAsync(1000))
    {
    	...//Do something
    }
}

Open in new window

What happens if the thread gets terminated while it's in "Do Something"?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Owner (Aidellio)
Most Valuable Expert 2015
Commented:
You might get lucky with the garbage collector, however, you'll most likely end up with a memory leak.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial