Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
runtime: lock_sema.go uses LIFO ordering for waking blocked Ms #13056
In the lock_sema.go implementation of mutexes, lock handles contention by adding the current M to the front of the linked list of waiting Ms, and then unlock wakes up the M at the front of the list. I.e., waiting Ms are awoken in LIFO order.
Is it worth changing unlock to awake the M at the end of the list to effect a FIFO order?
For comparison, lock_futex.go leaves resolving contention to the OS. On Linux, futex wakeup ordering doesn't seem to be guaranteed, but they do at least currently appear to use FIFO ordering (for threads with the same priority/nice level): http://lists.openwall.net/linux-kernel/2015/01/24/106
I don't see any obvious reason to change it. FIFO will get you better fairness, LIFO gets you better cache behavior. Unless there's a particular case where you think fairness is important, I'm inclined to leave it as is.
Is there a specific situation in which you noticed this?