>>27
Well no, in fact it makes the race condition worse. Many of the differences are going to be quite small indeed after coming out of that function.
I can think of a few enhancements:
First: tailor
A
and
K
http://en.wikipedia.org/wiki/Generalised_logistic_curve to the range of inputs. This adds some complexity, but it is nearly canceled by the act of spawning the
sleep
s and calculating
Y(t)
anyway.
Second: keep track of deltas upon return. When the gap is large enough relative to previous gaps
Feigenbaum constant? start a new partition, reiterate the process on each. (Note: multiple partitions can be sleep-sorted at the same time.) This will distribute the sleep times more evenly among elements, however: there is still no guarantee on most platforms that any kind of sleep sort will be free of race conditions, on any set of inputs, no matter the minimum range between elements.
Third, a meta-enhancement: make best-guesses at values for the range chosen in the first enhancement for the purposes of optimal calculations. Likewise establish a good terminal condition for the second, probably when all partitions have 1 element.
If you have a huge range in input with many clusters, I think these variations are optimal over anything less sophisticated. I've no idea how often that is the case (actually... does anyone have info on this?) but it seems like it's probably common enough. Even if the clustering isn't bad, the partitioning process deals with it automatically.