lock count is not working properly while analysing dump file which is generated by dotnet-dump. i.e. lock count column when executing clrthreads
Description
I tying to run clrthreads for below console application which is simulate deadlock so for thread1 and thread2 there should lock count as 1 for each
class Program
{
static object lock1 = new object();
static object lock2 = new object();
static void Main(string[] args)
{
Console.WriteLine("Starting application...");
Thread thread1 = new Thread(Thread1Work);
Thread thread2 = new Thread(Thread2Work);
thread1.Name = "thread1";
thread2.Name = "thread2";
thread1.Start();
thread2.Start();
thread1.Join();
thread2.Join();
Console.WriteLine("Exiting application...");
}
static void Thread1Work()
{
lock (lock1)
{
Console.WriteLine("Thread 1 acquired lock1");
Thread.Sleep(1000); // Simulate work
lock (lock2)
{
Console.WriteLine("Thread 1 acquired lock2");
}
}
}
static void Thread2Work()
{
lock (lock2)
{
Console.WriteLine("Thread 2 acquired lock2");
Thread.Sleep(1000); // Simulate work
lock (lock1)
{
Console.WriteLine("Thread 2 acquired lock1");
}
}
}
}`
Configuration
I am using linux system
output
> clrthreads
ThreadCount: 7
UnstartedThread: 0
BackgroundThread: 4
PendingThread: 0
DeadThread: 0
Hosted Runtime: no
Lock
DBG ID OSID ThreadOBJ State GC Mode GC Alloc Context Domain Count Apt Exception
0 1 c942 0000563E28BA0A60 2020020 Preemptive 00007F89728CAF58:00007F89728CB288 0000563E28B87D80 -00001 Ukn
6 2 c956 0000563E28BA7F50 21220 Preemptive 0000000000000000:0000000000000000 0000563E28B87D80 -00001 Ukn
7 4 c958 0000563E28BAC850 21220 Preemptive 0000000000000000:0000000000000000 0000563E28B87D80 -00001 Ukn (Finalizer)
2 5 c945 00007FC978001E90 20220 Preemptive 00007F89728CE038:00007F89728CF2C8 0000563E28B87D80 -00001 Ukn
9 6 c991 0000563E28C81A40 2021020 Preemptive 0000000000000000:0000000000000000 0000563E28B87D80 -00001 Ukn
10 7 c992 0000563E28C82C60 2021020 Preemptive 00007F89728CB2D0:00007F89728CD2A8 0000563E28B87D80 -00001 Ukn
11 8 c993 00007FC9780B4250 2021220 Preemptive 00007F897291FB40:00007F8972920FD0 0000563E28B87D80 -00001 Ukn
and now if I am running syncblk there is showing that there are two syncblock and owning thread are thread1 and thread2 respectively
syncblk
Index SyncBlock MonitorHeld Recursion Owning Thread Info SyncBlock Owner
1 00007F88C8002C88 3 1 0000563E28C82C60 c992 10 00007f89728cb2b8 System.Object
2 00007F88C8002CE0 3 1 0000563E28C81A40 c991 9 00007f89728cb2a0 System.Object
-----------------------------
Total 2
Free 0
The outputs of both are contradictory, Or let me correct if I am missing something
@kouvel @mikem8361
I was using on version
9.0.553101+5b61d34de04d6100e6003415f7d7e9c4b971afd4
Sorry, I haven't responded sooner. As it turns out the lock count column in the clrthreads command is always -1 except for very old .NET Core versions or .NET Framework. The runtime removed that lock count support 5 years ago.
The syncblk command looks like it is correct. Is there any other issues or can we close this issue?
Thank you @mikem8361!, then don't you think we should remove column it self because if someone is using/considering only "clrthreads" then it is giving false output.
The lock count == -1 basically means that it not available. We really don't want to change it or remove it. It has been this way for a long time.
Can we close this issue?
@mikem8361, if you don't want to remove it I don't have issue with that but there is not any meaning of that. you can close the issue.