go - Golang: goroutine infinite-loop -


When a fmt.Print () row is deleted from the code given below, So the code runs infinitely. Why?

  package main import "fmt" import "time" import "sync / atom" func main () {var ops uint64 = 0 i: = 0; I & lt; 50; I ++ {go func () {foromic.AddUint64 (and ops, 1) fmt.print ()}} ()} time Sleep (second time) opsFinal: = atomic.LoadUint64 (and ops) fmt. Println ("ops:", opsFinal)}  

this:

< Pre-> // Allow other goroutines to proceed Runtime.Gosched ()

fmt.print () plays a similar role, and it allows the main () to move forward.

An export GOMAXPROCS = 2 can help end the program even in the case of an infinite loop, as explained in "".

fmt.Print () clearly passes some control over syscall stuff


Yes, < Previous release in / p>

, a gorgetin that was always looping, could starve other gourdins on the same thread, a serious problem when GOMAXPROCS only one user thread was provided

In 1 1.2, it is partly addressed: the scheduler is sometimes called on the basis of entry on a function. This means that the one (non-inline) function in any loop can be pre-zero, allowing others to run on the same thread as goratinance.

Focus on the note (which I have placed): It is possible that for your loop in the atomic.AddUint64 (and ops, 1) inline There is no pre-vacancy.


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -