{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/16048","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/16048/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/16048/comments","events_url":"https://api.github.com/repos/golang/go/issues/16048/events","html_url":"https://github.com/golang/go/issues/16048","id":159915421,"number":16048,"title":"golang documents should make it clear whether or not reading/writing scalar type variables is atomic.","user":{"login":"yaxinlx","id":15266642,"avatar_url":"https://avatars.githubusercontent.com/u/15266642?v=3","gravatar_id":"","url":"https://api.github.com/users/yaxinlx","html_url":"https://github.com/yaxinlx","followers_url":"https://api.github.com/users/yaxinlx/followers","following_url":"https://api.github.com/users/yaxinlx/following{/other_user}","gists_url":"https://api.github.com/users/yaxinlx/gists{/gist_id}","starred_url":"https://api.github.com/users/yaxinlx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yaxinlx/subscriptions","organizations_url":"https://api.github.com/users/yaxinlx/orgs","repos_url":"https://api.github.com/users/yaxinlx/repos","events_url":"https://api.github.com/users/yaxinlx/events{/privacy}","received_events_url":"https://api.github.com/users/yaxinlx/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-06-13T10:08:11Z","updated_at":"2016-06-13T19:28:18Z","closed_at":null,"body":"1. What version of Go are you using (`go version`)?\r\n\r\n1.6\r\n\r\n2. What operating system and processor architecture are you using (`go env`)?\r\n\r\nDebian 8, Intel amd64 CPU.\r\n\r\n3. What did you do?\r\n\r\nI wrote a small program to test if reading/writing of scalar type variables is atomic.\r\n\r\n\tpackage main\r\n\r\n\timport \"runtime\"\r\n\r\n\tconst A, B = 12345, 67890\r\n\tvar c = A\r\n\r\n\tfunc f() {\r\n\t\tfor {\r\n\t\t\tc = A\r\n\t\t}\r\n\t}\r\n\r\n\tfunc g() {\r\n\t\tfor {\r\n\t\t\tc = B\r\n\t\t}\r\n\t}\r\n\r\n\tfunc main() {\r\n\t\tif runtime.NumCPU() < 3 {\r\n\t\t\truntime.GOMAXPROCS(3)\r\n\t\t}\r\n\t\t\r\n\t\tgo f()\r\n\t\tgo g()\r\n\t\t\r\n\t\tfor {\r\n\t\t\tt := c\r\n\t\t\tif t != A && t != B {\r\n\t\t\t\tprintln(\"!!!!!!!!!! c =\", t)\r\n\t\t\t\tpanic(\"c != A && c != B\")\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n4. What did you expect to see?\r\n\r\nexpect panic if reading/writing of scalar type variables is not atomic\r\n\r\n5. What did you see instead?\r\n\r\nnever panic.\r\n\r\n=================================\r\n\r\nThe official golang documents don't mention whether or not reading/writing scalar type variables is atomic. There are some pieces of vague info in other pages, such as:\r\n- https://golang.org/pkg/sync/atomic\r\n- https://golang.org/ref/mem\r\n\r\nMany 3rd party articles and group posts say reading/writing scalar type variables is NOT atomic.\r\nAre their statements correct for any processor architecture and OSes? or just for some ones?\r\n\r\nI really hope golang official documents can make clear on this point. \r\n"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/225682852","html_url":"https://github.com/golang/go/issues/16048#issuecomment-225682852","issue_url":"https://api.github.com/repos/golang/go/issues/16048","id":225682852,"user":{"login":"randall77","id":6889504,"avatar_url":"https://avatars.githubusercontent.com/u/6889504?v=3","gravatar_id":"","url":"https://api.github.com/users/randall77","html_url":"https://github.com/randall77","followers_url":"https://api.github.com/users/randall77/followers","following_url":"https://api.github.com/users/randall77/following{/other_user}","gists_url":"https://api.github.com/users/randall77/gists{/gist_id}","starred_url":"https://api.github.com/users/randall77/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/randall77/subscriptions","organizations_url":"https://api.github.com/users/randall77/orgs","repos_url":"https://api.github.com/users/randall77/repos","events_url":"https://api.github.com/users/randall77/events{/privacy}","received_events_url":"https://api.github.com/users/randall77/received_events","type":"User","site_admin":false},"created_at":"2016-06-13T19:28:18Z","updated_at":"2016-06-13T19:28:18Z","body":"We did go through some effort to make sure pointer writes are atomic.  Mostly to keep the garbage collector happy, but generally to prevent racy programs from going completely off the rails.  See #13160.\r\n"}}
{"actor":{"display_login":"randall77"}}