Does Go support volatile / non-volatile variables? -
i'm new language bear me.
i curious how go handles data storage available threads, in sense non-local variables can non-volatile, in java instance.
go has concept of channel, which, it's nature -- inter thread communication, means bypasses processor cache, , reads/writes heap directly.
also, have not found reference volatile in go lang documentation.
tl;dr: go not have keyword make variable safe multiple goroutines write/read it. use sync/atomic
package that. or better yet do not communicate sharing memory; instead, share memory communicating.
two answers two meanings of volatile
.net/java concurrency
some excerpts go memory model.
if effects of goroutine must observed goroutine, use synchronization mechanism such lock or channel communication establish relative ordering.
one of examples incorrect synchronization section example of busy waiting on value.
worse, there no guarantee write done ever observed main, since there no synchronization events between 2 threads. loop in main not guaranteed finish.
indeed, code(play.golang.org/p/k8ndh7duzq) never exits.
c/c++ non-standard memory
go's memory model not provide way address non-standard memory. if have raw access device's i/o bus you'll need use assembly or c safely write values memory locations. have ever needed in device driver precludes use of go.
Comments
Post a Comment