Hacker News new | ask | show | jobs
by ds300 4208 days ago
> With goroutines the cooperation is handled by the implementation/compiler -- i.e. Yield() calls are automatically inserted by the compiler -- rather than by the programmer manually by hand.

The compiler only inserts yeilds at some call sites. It's not a total solution like real preemptive scheduling, so you still need to be careful.

2 comments

That's old information; every function call causes the check now.
Newer Go versions (1.2 I think?) use preemptive scheduling so you don't have to do anything special: that's my point entirely.

Goroutines by specification have the potential to run all at the same time, in the exact way that OS-level threads do.

In older _implementatoins_ of Go, goroutines were not preemptively scheduled, and exactly as you say you had to be careful.