Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: lock_sema.go uses LIFO ordering for waking blocked Ms #13056

mdempsky opened this issue Oct 26, 2015 · 2 comments


Copy link

@mdempsky mdempsky commented Oct 26, 2015

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):


This comment has been minimized.

Copy link

@randall77 randall77 commented Oct 26, 2015

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?


This comment has been minimized.

Copy link
Member Author

@mdempsky mdempsky commented Oct 27, 2015

I'm not aware of it causing problems. I just happened to notice the LIFO ordering while reviewing the code, and thought I'd file an issue in the spirit of #11506.

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Nov 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.