503 threads are created with forkIO, with each thread creating one synchronised mutable variable (MVar) shared with the next thread in the ring. The last thread created returns an MVar to share with the first thread. Each thread reads from the MVar to its left, and writes to the MVar to its right.

Each thread then waits on a token to be passed from its neighbour. Tokens are then passed around the threads via the MVar chain N times, and the thread id of the final thread to receive a token is printed.