If there are no go statements, then the program is single threaded and thus thread safe. I assume that we are only using go built in concurrency primitives.
Otherwise:
A program is globals safe if any of this is true:
There are no global variables.
Globals are read only.
Globals are only ever modified by the same goroutine.
Globals are only accessed under the same mutex.
A program is thread-safe when it is globals safe AND any of these is also true:
Goroutines only ever get variables, as arguments or from channels, passed by copy.
After a reference is passed to another goroutine, the caller/sender goroutine never access that reference again (it transferred “ownership” of it).
I am trying to come up with a detailed definition of what a thread safe Go program is (and is not). One that a (go) tool could check by analyzing the code for me.
Otherwise:
A program is globals safe if any of this is true:
There are no global variables.
Globals are read only.
Globals are only ever modified by the same goroutine.
Globals are only accessed under the same mutex.
--
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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I am trying to come up with a detailed definition of what a thread safe Go program is (and is not). One that a (go) tool could check by analyzing the code for me.