Shortest Code that creates a Deadlock Write the shortest code to create a deadlock. Code execution must halt, so this doesn't work:

public class DeadlockFail extends Thread{ //Java code
    public static void main(String[]a){
        Thread t = new DeadlockFail();
        t.start();
        t.join();
    }
    //this part is an infinite loop; continues running the loop. 
    public void run(){while(true){}}
}


It doesn't need to be certain that the code goes into deadlock, just almost surely (if you run for infinite time, it will deadlock).
Dyalog APL (10)

⎕TSYNC⎕TID


⎕TSYNC makes the thread wait until the given thread ends,  ⎕TID gives the current thread.

Dyalog APL can recognize deadlocks though, so it immediately responds with

DEADLOCK


The fun thing is, you don't even need to spawn any extra threads, making the UI thread wait for itself is plenty.

If this is cheating and new threads are actually required, you can do it in 27 characters:

{∇⎕TSYNC&amp;{⎕TSYNC⎕TID+1}&amp;0}0


F &amp; x runs F in a new thread on value x, and returns the thread ID. So:


{⎕TSYNC⎕TID+1}&amp;0 creates a thread that will synchronize with the thread whose ID is one higher than its own, 
⎕TSYNC&amp; creates a new thread that will synchronize with the previous thread, and which gets an ID one higher than the thread that was just created (assuming nothing else is creating threads). 
∇ causes an infinite loop (so we keep creating threads until there's a deadlock).


This will deadlock as soon as the second thread gets created before the first one starts running, which is pretty soon:

9:DEADLOCK