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

Open
mdempsky opened this issue Oct 26, 2015 · 2 comments
Open

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

mdempsky opened this issue Oct 26, 2015 · 2 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.
Milestone

Comments

@mdempsky
Copy link
Member

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

@randall77
Copy link
Contributor

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?

@mdempsky
Copy link
Member Author

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
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.
Projects
None yet
Development

No branches or pull requests

4 participants