Skip to content

Commit

Permalink
Try to reduce chances of races in Stash
Browse files Browse the repository at this point in the history
Use `nqp::atomicbindattr` to replace `$!storage` with modified clone.
Though this doesn't fix the problem completely, it seemingly reduces the
chances of conflicting hash access.

Alongside, given `proto` to `ASSIGN-KEY` multi because we don't need
candidates from the parent `Hash`.
  • Loading branch information
vrurg committed May 13, 2022
1 parent 6fc2e6c commit 0293ae5
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/core.c/Stash.pm6
Expand Up @@ -34,6 +34,7 @@ my class Stash { # declared in BOOTSTRAP
)
}

proto method ASSIGN-KEY(Stash:D: $, $) {*}
multi method ASSIGN-KEY(Stash:D: Str:D $key, Mu \assignval) is raw {
my $storage := nqp::getattr(self,Map,'$!storage');
my \existing-key := nqp::atkey($storage, $key);
Expand All @@ -50,7 +51,7 @@ my class Stash { # declared in BOOTSTRAP
nqp::getattr(self, Hash, '$!descriptor')),
assignval)
);
nqp::bindattr(self, Map, '$!storage', $storage);
nqp::atomicbindattr(self, Map, '$!storage', $storage);
scalar
};
}
Expand Down

0 comments on commit 0293ae5

Please sign in to comment.