On Tue, Aug 18, 2015 at 9:56 AM, Roberto Zanotto <
roby...@gmail.com> wrote:
> It could be interesting to know why fair scheduling is not guaranteed by the
> language spec. Do you have some insight on the pros/cons or a pointer to a
> discussion?
> On Tuesday, August 18, 2015 at 6:18:10 PM UTC+2, Ian Lance Taylor wrote:
>>
>> On Tue, Aug 18, 2015 at 7:20 AM, 陆家靖 <
lujiaj...@gmail.com> wrote:
>> >
>> > The scheduler for goroutine is pre-emptive,
>> >
>> > so an empty for loop in goroutine will stuck the process if i set
>> > runtime.MAXGOPROCS(1)
>> >
>> > the re-schedule will happen only if i call any method in for-lop or the
>> > goroutine call runtime.Gosched() by itself
>> >
>> > so i wonder if the CFS could be used for schedule machanism
>> >
>> > if some goroutine run for a long time, the sched will switch to others
>>
>> There are two distinct issues here, and I'm not sure which one you are
>> asking.
>>
>> One issue is that, as you say, a goroutine that runs an infinite loop
>> without making any function calls or allocating any memory or using
>> any map or channel operations can currently run forever without being
>> preempted. That is a characteristic of the current gc implementation.
>> We could change it. I expect that one day we will. The only question
>> is how to do it most efficiently.
>>
>> A different issue is the scheduling algorithm used to select among
>> runnable goroutines. The current scheduling algorithm is reasonably
>> simple. We could use a more sophisticated one, but we wouldn't want
>> to simply adopt some standard algorithm wholesale. For Go it will
>> always be appropriate to consider channel operations when making
>> scheduling decisions.
>>
>> Ian
>