In the new example, goroutine 2 should get pre-empted at time.Sleep. goroutine 1 may hog a CPU however. There's an open issue about this, which is being worked on.
https://github.com/golang/go/issues/10958 I think it's always been the intent that from the programmer's perspective goroutines don't block one another at all; they're just like threads but cheaper -- and indeed most of the time you can write code that acts like that's true and never see a problem -- but the reality of the implementation is that right now it is possible to tight-loop and block other goroutines. -Ian Quoting Jingguo Yao (2019-02-22 03:31:55) > Yes, my fault. Thanks for pointing it out.� > What happens if I remove the fmt.Printf function calls to have the > following code: > package main > import ( > "fmt" > "runtime" > "time" > ) > func main() { > count := runtime.GOMAXPROCS(1) > fmt.Printf("GOMAXPROCS: %d\n", count) > � // goroutine 1 > go func() { > for { > } > }() > � // goroutine 2 > go func() { > for { > } > }() > time.Sleep(10 * time.Second) > } > Can goroutine 1 or goroutine 2 be preempted? If yes, by which > mechanism? > On Friday, February 22, 2019 at 4:20:12 PM UTC+8, Ian Denhardt wrote: > > Quoting Jingguo Yao (2019-02-22 03:17:33) > > � � Since both goroutines do not make any function calls > fmt.Printf is a function. > > -- > You received this message because you are subscribed to the Google > Groups "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to [1]golang-nuts+unsubscr...@googlegroups.com. > For more options, visit [2]https://groups.google.com/d/optout. > > Verweise > > 1. mailto:golang-nuts+unsubscr...@googlegroups.com > 2. https://groups.google.com/d/optout -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.