How waiting turns values into an order

In “sleep sort,” each number starts its own thread—a separate task the computer can run independently. A thread waits for a time proportional to its number, then prints it. Because shorter waits usually finish first, small numbers tend to appear before large ones. The output order is created by the timing of the tasks rather than by comparing pairs of values, as conventional sorting algorithms do.

For example, if the inputs are 3, 1, and 2, their threads wait for roughly three, one, and two time units. The thread for 1 is expected to print first, followed by 2 and 3.

Why the trick is not a dependable sorter

A computer does not wake threads at perfectly exact times. Its operating system schedules tasks, and other work can delay one thread while another runs. If two values are close together—or equal—their threads may print in an unexpected order. The method also takes time proportional to the largest value: sorting a list containing a very large number could mean waiting a very long time. And creating a separate thread for every input can consume substantial resources.

So sleep sort is best understood as a playful demonstration of concurrency: many tasks proceed at once, and their completion times shape the result. Its memorable catch is that the “sorted” list may arrive only after the largest number has finished waiting.