I have the book
Exam Ref 70-483 Programming in C#.
Listing 1-37(Page 33) shows an example of a deadlock.
public class Program
{
static void Main(string[] args)
{
object lockA = new object();
object lockB = new object();
var up = Task.Run(() =>
{
lock (lockA)
{
Thread.Sleep(1000);
lock (lockB)
{
Console.WriteLine("Locked A and B");
}
}
});
lock (lockB)
{
lock (lockA)
{
Console.WriteLine("Locked B and A");
}
}
up.Wait();
}
}
In the paragraph, it says: Because both locks are taken in reverse order, a deadlock occurs. The first
Task locks A and waits for B to become free. The main thread, however, has B locked and is waiting for A to be released.
However I tried the code, there was no deadlock at all.

Anything wrong?