Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know who owns a ReaderWriterLockSlim?

I'm writting an application that does extensive use of multithreading. Some of the threads share an observablecollection using a ReaderWriterLockSlim.

I'm having from time to time a deadlock and I need to know which is the thread holding the lock at the moment of the deadlock. How can I know this? I've looked at the object properties and nothing obvious was there. Currently all I know is which threads are waiting for the lock.

Thanks for your help!

EDIT: Of course I'm talking about finding it at debug time with all the debug information available.

like image 888
Ignacio Soler Garcia Avatar asked Dec 27 '22 00:12

Ignacio Soler Garcia


1 Answers

During your deadlock just look at the current threads in the thread debugging panel, go through your call stack and you'll find out which thread took the lock.

If you need to know the thread id in your code, you can always save it staticly, or inherit from readerwriterlockslim and add a thread property.

like image 103
Erez Robinson Avatar answered Jan 14 '23 14:01

Erez Robinson