Quoting David Finkel (2019-02-23 16:09:18)
>Not only is fmt.Printf a function call, but it makes a blocking
>syscall
>(write specifically),
>which gives the go runtime license to spin up a new OS thread and
>immediately schedule the other goroutine.
>runtime.GOMAXPROCS(1)
[The other responses have been excellent, but I wanted to point one thing
out.]
On Fri, Feb 22, 2019 at 3:17 AM Jingguo Yao wrote:
> Consider the following code which launches two goroutines. Each
> goroutine uses a for loop to print messages.
>
> package main
>
> import (
> "fmt"
>
Ian:
Thanks for your explanation.
On Saturday, February 23, 2019 at 1:13:04 AM UTC+8, Ian Denhardt wrote:
>
> 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.
>
>
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
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 {
}
On Fri, Feb 22, 2019 at 9:17 AM Jingguo Yao wrote:
> Without preemption, the M will run goroutine 1 or goroutine 2
continuously.
Not correct, there's also cooperative scheduling/yielding.
> The messages sent to the terminal should be all 1s or all 2s.
Nothing in the language specs mandates
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
Consider the following code which launches two goroutines. Each
goroutine uses a for loop to print messages.
package main
import (
"fmt"
"runtime"
"time"
)
func main() {
count := runtime.GOMAXPROCS(1)
fmt.Printf("GOMAXPROCS: %d\n", count)
// goroutine 1
go func() {
for