object A = new object();
object B = new object();
lock (B) Console.WriteLine("locked A, then B");
lock (A) Console.WriteLine("locked B, then A");
When you comment Thread.Sleep line you can easily understand whats happening.
A deadlock will only occur if you have more than one lock. You need a situation where both threads hold a resource that the other needs (which means there has to be a least two resources, and the two threads have to attempt to acquire them in a different order)