Skip to content

Commit

Permalink
Fix await-all: $remaining shouldn't go negative.
Browse files Browse the repository at this point in the history
Avoids some wasteful work as well as fixing a race.
  • Loading branch information
jnthn committed Jan 25, 2017
1 parent 658958e commit d088e0e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/Awaiter.pm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ my class Awaiter::Blocking does Awaiter {
my int $insert = nqp::atpos_i(indices, $i);
$handle.subscribe-awaiter(-> \success, \result {
$l.protect: {
if success {
if success && $remaining {
nqp::bindpos(results, $insert, result);
--$remaining;
$ready.signal unless $remaining;
Expand Down
2 changes: 1 addition & 1 deletion src/core/ThreadPoolScheduler.pm
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ my class ThreadPoolScheduler does Scheduler {
$handle.subscribe-awaiter(-> \success, \result {
my int $resume;
$l.protect: {
if success {
if success && $remaining {
nqp::bindpos(results, $insert, result);
--$remaining;
$resume = 1 unless $remaining;
Expand Down

0 comments on commit d088e0e

Please sign in to comment.