Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
runtime: golang scheduler is not preemptive - it's cooperative? #11462
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
Is this by design or are there plans to make Golang scheduler preemptive?
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 firstname.lastname@example.org
@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.