Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upruntime: golang scheduler is not preemptive - it's cooperative? #11462
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
davecheney
Jun 29, 2015
Contributor
Is this by design or are there plans to make Golang scheduler preemptive?
It is by design. There are no plans to make the scheduler fully preemtive, in normal situations, this is not a problem.
It is by design. There are no plans to make the scheduler fully preemtive, in normal situations, this is not a problem. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
RLH
Jun 29, 2015
Contributor
The traditional work around is to unroll the loop and add a Gosched. If
there are real world scenarios and available resources the compiler could
be taught how to do the transformation.
On Mon, Jun 29, 2015 at 7:19 AM, Dave Cheney notifications@github.com
wrote:
Is this by design or are there plans to make Golang scheduler preemptive?
It is by design. There are no plans to make the scheduler fully preemtive,
in normal situations, this is not a problem.—
Reply to this email directly or view it on GitHub
#11462 (comment).
|
The traditional work around is to unroll the loop and add a Gosched. If On Mon, Jun 29, 2015 at 7:19 AM, Dave Cheney notifications@github.com
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
aclements
Jun 29, 2015
Member
@GoranP, you can think of the Go scheduler as being partially preemptive. It's by no means fully cooperative, since user code generally has no control over scheduling points, but it's also not able to preempt at arbitrary points. Currently, the general rule is that it can preempt at function calls, since at that point there's very little state to save or restore, which makes preemption very fast and dramatically simplifies some aspects of garbage collection. Your loop happens to contain none of these controlled preemption points, which is why the scheduler can't preempt it, but as @davecheney mentioned, this is fairly uncommon in real code (though by no means unheard of). We would like to detect loops like this and insert preemption points, but that work just hasn't happened yet. The issue for tracking that work (or, at least, the desire to do it :) is #10958.
Duplicate of #10958.
|
@GoranP, you can think of the Go scheduler as being partially preemptive. It's by no means fully cooperative, since user code generally has no control over scheduling points, but it's also not able to preempt at arbitrary points. Currently, the general rule is that it can preempt at function calls, since at that point there's very little state to save or restore, which makes preemption very fast and dramatically simplifies some aspects of garbage collection. Your loop happens to contain none of these controlled preemption points, which is why the scheduler can't preempt it, but as @davecheney mentioned, this is fairly uncommon in real code (though by no means unheard of). We would like to detect loops like this and insert preemption points, but that work just hasn't happened yet. The issue for tracking that work (or, at least, the desire to do it :) is #10958. Duplicate of #10958. |
aclements
closed this
Jun 29, 2015
mikioh
changed the title from
golang scheduler is not preemptive - it's cooperative?
to
runtime: golang scheduler is not preemptive - it's cooperative?
Jun 30, 2015
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
GoranP
commented
Jun 30, 2015
|
Thx guys for clarification. |
GoranP commentedJun 29, 2015
If you run this code with only one go routine:
Scheduler is paralized, and Printf is NOT printed after 100ms as expected, but after all job is done in cpuintensive() go routine.
But if programmer insert
runtime.Gosched()in intensive for loop of routine, cooperative scheduler works fine.Is this by design or are there plans to make Golang scheduler preemptive?