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.