On Tue, Feb 19, 2019 at 9:34 AM Manlio Perillo <manlio.peri...@gmail.com> wrote:
>
> The Go language specification never mentions undefined behavior, however
> Ian Lance Taylor wrote, in [1], that:
>
>  - if your program has a race condition, the behavior is undefined.
>
> [1] https://groups.google.com/forum/#!topic/golang-nuts/MB1QmhDd_Rk:

Although I did say that, I want to clarify that I'm not really
comfortable with saying that Go ever has undefined behavior in the
sense that C does.  Race conditions in general are covered by the Go
memory model at https://golang.org/ref/mem.  That document explains
how you need to write your program to guarantee certain behavior.  If
you don't write your program that way, the results are unspecified.
However, I don't think they are undefined in the sense of C.  For
example, if two different goroutines write to the same global variable
then we don't know which value that variable will get, and we don't
necessarily know for sure that it will get one value or the other--it
may in some cases get some peculiar combination of the values.  And
the program may panic or even simply crash.  But I'm not comfortable
saying that the program is undefined in the sense of C, in which
anything at all may happen.

In particular I'm not comfortable saying that a Go compiler may
optimize in the way that a C compiler may, by assuming that undefined
behavior may never happen.  I'm not sure that Go will ever have
undefined behavior in that sense.

Ian

-- 
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 an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to