[experiment/WIP] runtime: add SetYieldPriority #13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Typically goroutines which yielded their execution to the runtime until spare execution capacity became available are resumed in the order in which they yielded, i.e. FIFO. That said, when or even if this happens is unpredictable: a gorotuine opting to yield does so with the explicit knowledge it could be paused indefinitely under sustained overload conditions, and as such, yielding is only done cooperatively by the calling goroutine at locations it knows to be safe to pause, i.e. not in critical sections or while holding locks. In general, the runtime scheduler does not offer user-facing facilities to prioritize relative scheduling of multiple goroutines as this opens it up to complicated questions of priority inversions, but voluntary yields allow the caller to determine when and where it is safe to yield, avoiding these issues.
Thus, within the narrowly defined scope of the resumption order of goroutines which have explicitly yielded -- which is already assumed to imply that deprioritizing them for the duration of a yield should not introduce priority inversions -- introducing relative priority between goroutines insofar allowing control over the oder in which they are resumed as capacity becomes available to do so can be feasible.