danielpiron / sleepsort

Implementations of "sleepsort" in multiple languages to practice basic concurrency programming.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SleepSort

I first came across the concept of a sleepsort while viewing a recording of the Kevlin Henney talk "Get Kata". The talk revolves around the value of practice exercises for software engineers. During the Q&A portion of the talk, a member of the audience brings up sleep sort and, among other things, Kevlin has this to say about it:

It is beautiful in a way that is insane.

You can catch the sleepsort portion at 1:11:10 of the talk.

Kevlin shares an Unix shell implementation that looks like this:

while [ -n "$1" ]
do
    (sleep $1; echo $1) &
    shift
done
wait

The program expects a list of numbers. For each number N, a sub-shell is spawned with a single task. Wait for N seconds, then display N. Lower numbers will naturally appear earlier than higher numbers with the resulting output being a sorted list of numbers.

Is this practical? Of course not. If your highest value is around 3600, for example, you are looking at waiting an hour for results, even with two value. However, an efficient sort is that what I am looking for. I feel sleepsort makes for a rather elegant means for practicing concurrent programming in a variety of languages.

Goal & Purpose

This repository will host my various attempts at implementing sleepsort. I may reimplement sleepsort multiple times in the same language.

  • Each implementation will be self contained (i.e. One source file per implementation)
  • Interface will follow Kevlin Henney's shell example (i.e. Numbers are given as command-line arguments)
  • Any necessary build parameters will be provided as comments towards the begin of source
  • Implementations will strive to be as simple as allowable by standard language features.

About

Implementations of "sleepsort" in multiple languages to practice basic concurrency programming.


Languages

Language:Python 100.0%