{"action":"created","issue":{"url":"https://api.github.com/repos/tc39/ecmascript_sharedmem/issues/56","repository_url":"https://api.github.com/repos/tc39/ecmascript_sharedmem","labels_url":"https://api.github.com/repos/tc39/ecmascript_sharedmem/issues/56/labels{/name}","comments_url":"https://api.github.com/repos/tc39/ecmascript_sharedmem/issues/56/comments","events_url":"https://api.github.com/repos/tc39/ecmascript_sharedmem/issues/56/events","html_url":"https://github.com/tc39/ecmascript_sharedmem/issues/56","id":130018351,"number":56,"title":"Load elimination via single thread valid only optimization","user":{"login":"taisel","id":13305116,"avatar_url":"https://avatars.githubusercontent.com/u/13305116?v=3","gravatar_id":"","url":"https://api.github.com/users/taisel","html_url":"https://github.com/taisel","followers_url":"https://api.github.com/users/taisel/followers","following_url":"https://api.github.com/users/taisel/following{/other_user}","gists_url":"https://api.github.com/users/taisel/gists{/gist_id}","starred_url":"https://api.github.com/users/taisel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/taisel/subscriptions","organizations_url":"https://api.github.com/users/taisel/orgs","repos_url":"https://api.github.com/users/taisel/repos","events_url":"https://api.github.com/users/taisel/events{/privacy}","received_events_url":"https://api.github.com/users/taisel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":24,"created_at":"2016-01-30T17:59:45Z","updated_at":"2016-02-05T18:46:51Z","closed_at":null,"body":"https://github.com/taisel/IodineGBA/blob/0af5eaaaf08cc3a1a024974c354e2ae5554c1f3f/IodineGBA/core/graphics/Worker.js#L98\r\n\r\nAlready got bitten by load elimination, rather than addition. Had to write out a specific comment mentioning it on that line, as I originally had the load as relaxed, since only one thread ever writes into it. There are other various futex/atomic calls that *should* flush out the producer thread into posting an updated value of the load that got optimized away, it's just IonMonkey removed it thinking it would never change. I wish we had lower level Atomics to avoid this kind of thing, as I try to optimize around blanket full fences.\r\n\r\nBasically if the statement was:\r\ngfxLinesCPU = gfxLineCounter[0]\r\n\r\ninstead of:\r\ngfxLinesCPU =Atomics.load(gfxLineCounter, 0)\r\n\r\nIonMonkey never reloads the value, because it doesn't consider another thread as existing in its optimization context. \r\n\r\nThe reason I find this in the gray area is, because in a sort of manner,  deceptive to have a programmer explicitly use a shared array buffer to back a variable and have the optimizer not take that into account. I'd test v8 for Google Chrome as well, but code error via https://code.google.com/p/chromium/issues/detail?id=31666 (Edit: no longer true, there's a fallback now that hoists code from a worker to main and the subworker to the next worker up)"},"comment":{"url":"https://api.github.com/repos/tc39/ecmascript_sharedmem/issues/comments/180494743","html_url":"https://github.com/tc39/ecmascript_sharedmem/issues/56#issuecomment-180494743","issue_url":"https://api.github.com/repos/tc39/ecmascript_sharedmem/issues/56","id":180494743,"user":{"login":"taisel","id":13305116,"avatar_url":"https://avatars.githubusercontent.com/u/13305116?v=3","gravatar_id":"","url":"https://api.github.com/users/taisel","html_url":"https://github.com/taisel","followers_url":"https://api.github.com/users/taisel/followers","following_url":"https://api.github.com/users/taisel/following{/other_user}","gists_url":"https://api.github.com/users/taisel/gists{/gist_id}","starred_url":"https://api.github.com/users/taisel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/taisel/subscriptions","organizations_url":"https://api.github.com/users/taisel/orgs","repos_url":"https://api.github.com/users/taisel/repos","events_url":"https://api.github.com/users/taisel/events{/privacy}","received_events_url":"https://api.github.com/users/taisel/received_events","type":"User","site_admin":false},"created_at":"2016-02-05T18:46:51Z","updated_at":"2016-02-05T18:46:51Z","body":"The race (if using the non-atomic load instead of atomic) is supposed to be bounded (by design), such that it's allowed to go out of synchronization with other variables, but gets synchronized past a certain code block, see the surrounding futexWait and atomic loads and stores that should memory fence. The lack of updates spans across multiple futexes and atomic loads and stores of various code blocks, and lags enough behind (well it never gets updated) the gfxCommandCounters variable to cause funky line skip logic."}}