• Austin Clements's avatar
    runtime: fix mark 2 completion in fractional/idle workers · cf225a17
    Austin Clements authored
    Currently fractional and idle mark workers dispose of their gcWork
    cache during mark 2 after incrementing work.nwait and after checking
    whether there are any workers or any work available. This creates a
    window for two races:
    
    1) If the only remaining work is in this worker's gcWork cache, it
       will see that there are no more workers and no more work on the
       global lists (since it has not yet flushed its own cache) and
       prematurely signal mark 2 completion.
    
    2) After this worker has incremented work.nwait but before it has
       flushed its cache, another worker may observe that there are no
       more workers and no more work and prematurely signal mark 2
       completion.
    
    We can fix both of these by simply moving the cache flush above the
    increment of nwait and the test of the completion condition.
    
    This is probably contributing to #11694, though this alone is not
    enough to fix it.
    
    Change-Id: Idcf9656e5c460c5ea0d23c19c6c51e951f7716c3
    Reviewed-on: https://go-review.googlesource.com/12646Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
    cf225a17
mgc.go 54.9 KB