Skip to content

Commit

Permalink
Keeps original test, addressing @vrurg review
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed Apr 14, 2021
1 parent bfe0121 commit 2fcb0dd
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion S17-lowlevel/lock.t
Expand Up @@ -7,7 +7,7 @@ use Test;
# start {...}), Channels and Supplies. Thank you!
#-------------------------------------------------------------------------------

plan 23;
plan 24;

{
my $l = Lock.new;
Expand Down Expand Up @@ -88,6 +88,42 @@ plan 23;
is @log.join(','), 'ale,porter,stout', 'Condition variable worked';
}

{
my $times = 100;
my $tried;
my $failed;
for ^$times {
my $l = Lock.new;
my $c = $l.condition;
my $now1;
my $now2;
my $counter = 0;
my $t1 = Thread.start({
$l.protect({
while ($counter == 0 ) {
$c.wait();
}
$now1 = now;
});
});

my $t2 = Thread.start({
$l.protect({
$counter++;
$c.signal();
});
});

$t1.join();
$now2 = now;
$t2.join();

$tried++;
last if $failed = ( !$now1.defined or $now1 > $now2 );
}
ok !$failed, "Thread 1 never ran after it was tried $tried times";
}

{
my $times = 100;
my $tried;
Expand Down

0 comments on commit 2fcb0dd

Please sign in to comment.