Skip to content

Commit

Permalink
Fix potential "test run out of order" in 01-thread.t
Browse files Browse the repository at this point in the history
Without synchronization, it may happen that two ok() run concurrently and
confuse the test count with one ok() coming in between the update of the global
test counter and the actual print of the test result.
  • Loading branch information
niner committed Mar 20, 2018
1 parent 200e4cf commit 66be87d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion t/concurrency/01-thread.t
Expand Up @@ -25,11 +25,14 @@ plan(24);

# 4 tests
{
my int $done := 0;
my $t := nqp::newthread({
ok(1, 'Can write to STDOUT in child thread')
1 until $done;
ok(1, 'Can write to STDOUT in child thread');
}, 0);
ok(1, 'Can write to STDOUT in parent thread before threadrun');
nqp::threadrun($t);
$done := 1;
ok(1, 'Can write to STDOUT in parent thread after threadrun');
nqp::threadjoin($t);
ok(1, 'Can write to STDOUT in parent thread after threadjoin');
Expand Down

0 comments on commit 66be87d

Please sign in to comment.