Skip to content

Instantly share code, notes, and snippets.

@Cijin
Created March 15, 2022 01:55
Show Gist options
  • Save Cijin/5d5c622c60ccda27a0d2f95b54fcdf1d to your computer and use it in GitHub Desktop.
Save Cijin/5d5c622c60ccda27a0d2f95b54fcdf1d to your computer and use it in GitHub Desktop.
Yield Processor: Note to future self.

When reading about Race conditions in go, I came across runtime.gosched() which I glanced over but did not clearly understand. So went through the docs to understand what it does. This is what the docs says it does:

Gosched yields the processor, allowing other goroutines to run. It does not suspend the current goroutine, 
so execution resumes automatically.

When I read this, I did not clearly understand what it does, cause I did not understand what yield meant. This is the best definition that made sense in this context: To give over possession of, as in deference or defeat; surrender.

Still not entirely clear as to what yielding the processor means. So I searched for those terms exactly Yield processor. Came across this stackoverflow answer that made things crystal clear. So to reinforce it for myself, I'm going to note down my best understanding of it.

Yield is in this context means yield execution so that other processes can run. So in the context of the a go program if there are other goroutines running, execution will switch to those processes till that process yields the processor and the initial go routine can continue execution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment