aboutsummaryrefslogtreecommitdiff
path: root/challenge-142/e-choroba/perl/ch-2.pl
blob: 4e7fce46d39afb54536b2fdc6d36adcda2fa744e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/perl
use warnings;
use strict;

use threads;
use threads::shared;

use Test2::V0;
plan 1;

sub sleep_sort {
    my @sorted :shared;
    my @threads;
    for my $n (@_) {
        push @threads,
             'threads'->create(sub { sleep $n; push @sorted, $n });
    }
    $_->join for @threads;
    return @sorted
}

my @numbers = map 1 + int rand 20, 1 .. 50;
is [sleep_sort(@numbers)], [sort { $a <=> $b } @numbers], 'same';