■2011-05-20
* [Perl] sleep sortのithread版
常識を覆すソートアルゴリズム!その名も"sleep sort"!から。 threads版がないのが不憫なのでここにひっそり書いておきます。
use 5.010;
use strict;
use warnings;
use threads;
use threads::shared;
use Time::HiRes qw(sleep);
my @thrs;
my @values : shared;
for ( @ARGV ) {
push @thrs, threads->new(sub {
sleep $_[0] / 10;
push @values, $_[0];
}, $_);
}
$_->join for @thrs;
say join( " ", @values );
[]

