{"action":"closed","issue":{"url":"https://api.github.com/repos/golang/go/issues/14977","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/14977/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/14977/comments","events_url":"https://api.github.com/repos/golang/go/issues/14977/events","html_url":"https://github.com/golang/go/issues/14977","id":143729344,"number":14977,"title":"proposal: atomic keyword","user":{"login":"OneOfOne","id":1080443,"avatar_url":"https://avatars.githubusercontent.com/u/1080443?v=3","gravatar_id":"","url":"https://api.github.com/users/OneOfOne","html_url":"https://github.com/OneOfOne","followers_url":"https://api.github.com/users/OneOfOne/followers","following_url":"https://api.github.com/users/OneOfOne/following{/other_user}","gists_url":"https://api.github.com/users/OneOfOne/gists{/gist_id}","starred_url":"https://api.github.com/users/OneOfOne/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OneOfOne/subscriptions","organizations_url":"https://api.github.com/users/OneOfOne/orgs","repos_url":"https://api.github.com/users/OneOfOne/repos","events_url":"https://api.github.com/users/OneOfOne/events{/privacy}","received_events_url":"https://api.github.com/users/OneOfOne/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-03-26T16:48:37Z","updated_at":"2016-03-27T20:25:57Z","closed_at":"2016-03-27T20:25:57Z","body":"* disclaimer: I'm horrible at writing essays and proposals, so take this with a grain of salt. \r\n\r\n### Abstract\r\n\r\nWith the growing number of processor cores, many developers use atomics rather than mutex/cond when they can.\r\n\r\n### Background\r\n\r\nFor primitive types, we have `sync/atomic`, which provides Load/Store/Swap/CAS, however, for other types we only have `atomic.Value`, which only provides Load/Store and the added overhead of runtime type assertion since it uses `interface{}`\r\n\r\n### Proposal\r\nHere comes the atomic keyword (more like chan, but it can be something else really):\r\n\r\n```\r\nv := make(atomic *SomeStruct)\r\nov := v.Swap(&SomeStruct)\r\nif v.CompareAndSwap(nil, &SomeStruct) { }\r\n\r\nv2 := v.Load()\r\nv.Store(v3)\r\n// or maybe?\r\nv2 := v // implicit v.Load()?\r\nv := v3 // implicit v.Store(v3)\r\n```\r\n\r\n### Implementation \r\n\r\nIt'd be implemented much like `atomic.Value` internally, probably using a spinlock for CAS and Swap operations, with the added runtime magic to handle types directly instead of using interface{}.\r\n\r\nIdeas? Feedback?"}}