The Santa Claus Problem

Simon Peyton Jones, in "Beautiful Concurrency", [1] a chapter of
Beautiful Code, presents the Santa Claus problem and a solution:

A well-known example is the so-called Santa Claus problem,
originally attributed to Trono: [2]

Santa repeatedly sleeps until wakened by either all of his nine
reindeer, back from their holidays, or by a group of three of
his ten elves. If awakened by the reindeer, he harnesses each
of them to his sleigh, delivers toys with them and finally
unharnesses them (allowing them to go off on holiday). If
awakened by a group of elves, he shows each of the group into
his study, consults with them on toy R&D and finally shows them
each out (allowing them to go back to work). Santa should give
priority to the reindeer in the case that there is both a gorup
of elves and a group of reindeer waiting.

His solution is presented in Haskell, using Software Transactional
Memory:

[2008-02-06: As liyang pointed out, I had a bug in my original
re-typing of the Haskell solution, as presented on this page. Oddly,
the second version that I was using when I was testing the two
solutions and writing this page did not have that typo. I do not
know how the bug got into this version, but I have fixed it now.]

Erlang

For comparison, I would like to present the first piece of Erlang code
I have written:

Erlang uses message passing for communication between threads, and to
my eye leads to a more understandable solution. At least, it may not
have the beauty of the Haskell code, but at least it has a certain
native charm.

One significant difference is in the bias towards reindeer. Peyton
Jones says,

The choice is made by the orElse, which first attempts to choose
the reindeer (thereby giving them priority), and otherwise chooses
the elves.

In the Erlang code, I had to specifically add a receive expression to
allow the reindeer to starve the elves of Santa's attention; otherwise
the priority would be decided by the message queue, fairly. My
question is how to achieve fairness in the STM version?

Also according to Google, Richard O'Keefe has another solution to the
Santa Claus problem in Erlang, Erlang Eases Expediting Elves, Reduces
Reindeer Rage. His solution is somewhat shorter than mine, and uses
two "secretary" processes to manage the groups of reindeer and elves.
On the other hand, it seems as simple and easy to read; we seem to
have both come to the same conclusion.

Finally, Luke Gorrie (on Lambda the Ultimate!) presents a third
Erlang solution along with a sketch of a Lisp simulation. I have not
really analyzed this solution and I do not know if it handles the
priorities complication, but it is relatively easy on the eyes.

Santa Claus sleeps in his shop up at the North Pole, and can
only be wakened by either all nine reindeer being back from
their year long vacation on the beaches of some tropical
island in the South Pacific, or by some elves who are having
some difficulties making the toys. One elf's problem is never
serious enough to wake up Santa (otherwise, he may never get
any sleep), so, the elves visit Santa in a group of
three. When three elves are having their problems solved, any
other elves wishing to visit Santa must wait for those elves
to return. If Santa wakes up to find three elves waiting at
his shop's door, along with the last reindeer having come back
from the tropics, Santa has decided that the elves can wait
until after Christmas, because it is more important to get his
sleigh ready as soon as possible. (It is assumed that the
reindeer don't want to leave the tropics, and therefore they
stay there until the last possible moment. They might not even
come back, but since Santa is footing the bill for their year
in paradise ... This could also explain the quickness in their
delivering of presents, since the reindeer can't wait to get
back to where it is warm.) The penalty for the last reindeer
to arrive is that it must get Santa while the others wait in a
warming hut before being harnessed to the sleigh.