Goroutines are cooperatively scheduled. Does that mean that goroutines that don't yield execution will cause goroutines to run one by one?

前端 未结 4 621
甜味超标
甜味超标 2020-12-28 18:53

From: http://blog.nindalf.com/how-goroutines-work/

As the goroutines are scheduled cooperatively, a goroutine that loops continuously can starve other

4条回答
  •  春和景丽
    2020-12-28 19:22

    @Akavall Try adding sleep after creating dumb goroutine, goruntime never executes sum_up goroutines.

    From that it looks like go runtime spawns next go routines immediately, it might execute sum_up goroutine until go runtime schedules dumb() goroutine to run. Once dumb() is scheduled to run then go runtime won't schedule sum_up goroutines to run, as dumb runs for{}

提交回复
热议问题