my experience with runtime.mutex values is that process-wide demand for a single mutex can slow the program to a crawl. 引用: https://github.com/golang/go/issues/68578
takes to go to sleep is over 100 times longer than the runtime's fastest critical sections. 引用: https://github.com/golang/go/issues/68578 • lock2で、スリープするまでのスピン時間 > クリティカルセクション (ロックを取ってからアンロックするまでの時間)×100〜となっている。 • この差が問題を引き起こす。
Having the state word in cache for read access requires it not be writeable by any other processors. Writing to that memory location requires the hardware to invalidate all cached copies of that memory, one in each processor that had loaded it for reading. 引用: https://go.googlesource.com/proposal/+/master/design/68578-mutex-spinbit.md
• このビットが立っていれば、unlockで追加のスレッドを起こさない Expand the mutex state word to include a new flag, "spinning". Use the "spinning" bit to communicate whether one of the waiting threads is awake and looping while trying to acquire the lock. 引用: https://go.googlesource.com/proposal/+/master/design/68578-mutex-spinbit.md