• Austin Clements's avatar
    runtime: make rwmutex work on Ms instead of Gs · 80832974
    Austin Clements authored
    Currently runtime.rwmutex is written to block the calling goroutine
    rather than the calling thread. However, rwmutex was intended to be
    used in the scheduler, which means it needs to be a thread-level
    synchronization primitive.
    
    Hence, this modifies rwmutex to synchronize threads instead of
    goroutines. This has the consequence of making it write-barrier-free,
    which is also important for using it in the scheduler.
    
    The implementation makes three changes: it replaces the "w" semaphore
    with a mutex, since this was all it was being used for anyway; it
    replaces "writerSem" with a single pending M that parks on its note;
    and it replaces "readerSem" with a list of Ms that park on their notes
    plus a pass count that together emulate a counting semaphore. I
    model-checked the safety and liveness of this implementation through
    >1 billion schedules.
    
    For #20738.
    
    Change-Id: I3cf5a18c266a96a3f38165083812803510217787
    Reviewed-on: https://go-review.googlesource.com/47071
    Run-TryBot: Austin Clements <austin@google.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
    80832974
export_test.go 7.74 KB