News for hackers. Stuff that matters.
Re:Cmd/compile: Go 1.8 regression: sync/atomic loop elided by kevhito on Monday February 20, 2017 @05:40PM (#13691680)
I don't understand. By your argument, and some of the replies, because "you're not guaranteed a goroutine will run at any particular time", the compiler is free to elide any suffix of a goroutine's code, even if that code has visible side effects.

I think there is something more specific to atomic going on here, where the same kinds of optimizations are already forbidden for other kinds of visible side effects like printing.

Re:Cmd/compile: Go 1.8 regression: sync/atomic loop elided by omginternets on Monday February 20, 2017 @07:13PM (#13692165)
>even if that code has visible side effects

The argument is that you told it to do that. "Just print whenever", and whenever can mean never if the world dies prematurely.

Re:Cmd/compile: Go 1.8 regression: sync/atomic loop elided by kevhito on Monday February 20, 2017 @08:43PM (#13692549)
So you are telling me a valid optimization for Go is to elide the entire contents of all goroutines?

And by that argument, since main() itself is an implicitly-called goroutine (so far as I know), then the compiler can elide the entire contents of main() too, and then the rest of the contents of the program.

</reductio-ad-absurdum>

Re:Cmd/compile: Go 1.8 regression: sync/atomic loop elided by NateDad on Monday February 20, 2017 @11:12PM (#13693224)
Well, sort of, yes. https://play.golang.org/p/qyfqZA5pww

  func main() {
    go fmt.Println("Hi!")
  }
This is a valid go program (eliding import etc), and it'll almost never print anything.

This is actually a classic mistake when starting with goroutines - not adding synchronization to make sure your main goroutine doesn't exit before any spawned goroutines.

Re:Cmd/compile: Go 1.8 regression: sync/atomic loop elided by CasualSuperman on Saturday February 25, 2017 @09:54AM (#13731795)
Yes, but then the program would never terminate, because that's what happens at the end of main. If main returns, it's saying that the rest of the code in main has executed.