[commit: ghc] ghc-7.10: Fix for crash in setnumcapabilities001 (6de9b6e)
git at git.haskell.org
git at git.haskell.org
Fri Jun 26 19:25:51 UTC 2015
Repository : ssh://git@git.haskell.org/ghc
On branch : ghc-7.10
Link : http://ghc.haskell.org/trac/ghc/changeset/6de9b6eb59c7525255e6780c57fa361ec108fc88/ghc
>---------------------------------------------------------------
commit 6de9b6eb59c7525255e6780c57fa361ec108fc88
Author: Simon Marlow <marlowsd at gmail.com>
Date: Fri Jun 19 14:41:32 2015 +0100
Fix for crash in setnumcapabilities001
getNewNursery() was unconditionally incrementing next_nursery, which
is normally fine but it broke an assumption in
storageAddCapabilities(). This manifested as an occasional crash in
the setnumcapabilities001 test.
(cherry picked from commit be0ce8718ea40b091e69dd48fe6bc62b6b551154)
>---------------------------------------------------------------
6de9b6eb59c7525255e6780c57fa361ec108fc88
rts/sm/Storage.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/rts/sm/Storage.c b/rts/sm/Storage.c
index 50926b7..297e584 100644
--- a/rts/sm/Storage.c
+++ b/rts/sm/Storage.c
@@ -549,6 +549,7 @@ allocNursery (bdescr *tail, W_ blocks)
STATIC_INLINE void
assignNurseryToCapability (Capability *cap, nat n)
{
+ ASSERT(n < n_nurseries);
cap->r.rNursery = &nurseries[n];
cap->r.rCurrentNursery = nurseries[n].blocks;
newNurseryBlock(nurseries[n].blocks);
@@ -699,14 +700,19 @@ resizeNurseries (W_ blocks)
rtsBool
getNewNursery (Capability *cap)
{
- StgWord i = atomic_inc(&next_nursery, 1) - 1;
- if (i >= n_nurseries) {
- return rtsFalse;
+ StgWord i;
+
+ for(;;) {
+ i = next_nursery;
+ if (i >= n_nurseries) {
+ return rtsFalse;
+ }
+ if (cas(&next_nursery, i, i+1) == i) {
+ assignNurseryToCapability(cap, i);
+ return rtsTrue;
+ }
}
- assignNurseryToCapability(cap, i);
- return rtsTrue;
}
-
/* -----------------------------------------------------------------------------
move_STACK is called to update the TSO structure after it has been
moved from one place to another.
More information about the ghc-commits
mailing list