{"action":"created","issue":{"url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/3794","repository_url":"https://api.github.com/repos/dolphin-emu/dolphin","labels_url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/3794/labels{/name}","comments_url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/3794/comments","events_url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/3794/events","html_url":"https://github.com/dolphin-emu/dolphin/pull/3794","id":150623829,"number":3794,"title":"Core: Add synchronization to state changes (Fix Frame Step and FIFO Player -  Issue 8718)","user":{"login":"EmptyChaos","id":17393426,"avatar_url":"https://avatars.githubusercontent.com/u/17393426?v=3","gravatar_id":"","url":"https://api.github.com/users/EmptyChaos","html_url":"https://github.com/EmptyChaos","followers_url":"https://api.github.com/users/EmptyChaos/followers","following_url":"https://api.github.com/users/EmptyChaos/following{/other_user}","gists_url":"https://api.github.com/users/EmptyChaos/gists{/gist_id}","starred_url":"https://api.github.com/users/EmptyChaos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EmptyChaos/subscriptions","organizations_url":"https://api.github.com/users/EmptyChaos/orgs","repos_url":"https://api.github.com/users/EmptyChaos/repos","events_url":"https://api.github.com/users/EmptyChaos/events{/privacy}","received_events_url":"https://api.github.com/users/EmptyChaos/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":22,"created_at":"2016-04-24T04:22:49Z","updated_at":"2016-05-16T15:10:58Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/dolphin-emu/dolphin/pulls/3794","html_url":"https://github.com/dolphin-emu/dolphin/pull/3794","diff_url":"https://github.com/dolphin-emu/dolphin/pull/3794.diff","patch_url":"https://github.com/dolphin-emu/dolphin/pull/3794.patch"},"body":"<p><del>[Needs PR #3769 as well]</del></p>\r\n\r\nAlternative to #3712 that fixes the underlying race. The basic problem is that `CPU::EnableStepping` is a non-atomic function that was only designed to be called from the Host thread so it races when called from the CPU/GPU or any other system thread. One thread will go through and stop the CPU, mute the audio and pause the FIFO while the other unpauses the CPU, unmutes the audio and unpauses the FIFO resulting in a random final state (e.g. CPU running with no video, CPU and video running with no audio). Other functions which depend on `EnableStepping` like `Core::SetState` and `CPU::Break` inherit those bugs.\r\n\r\nThis PR makes the implicit design choices explicit: `CPU::EnableStepping`, `Core::SetState` and `Core::PauseAndLock` are now Host thread only. `CPU::Break` has been rewritten as a threadsafe way for system threads to do `EnableStepping(true)` only.\r\n\r\n----\r\n\r\n<del>I've removed the anti-deadlock hack (lock timeout) for testing purposes but that needs to go back in before this can be merged.</del> A known source of deadlocks is `wxMsgAlert` (CPU `PanicAlert`s, GUI tries to CORE_PAUSE/PauseAndLock/EnableStepping and deadlocks waiting for the CPU waiting for the GUI waiting for the CPU...), this is somewhat intractable to fix since it requires one of 1) removing wxMsgAlert entirely, 2) shifting Core::SetState/CPU::EnableStepping/Core::PauseAndLock calls onto a dedicated background thread so that the GUI never calls a blocking Core function directly, or 3) spawning an external helper process to display the messages.\r\n\r\n<!-- Reviewable:start -->\r\n---\r\nThis change is [<img src=\"https://reviewable.io/review_button.svg\" height=\"35\" align=\"absmiddle\" alt=\"Reviewable\"/>](https://reviewable.io/reviews/dolphin-emu/dolphin/3794)\r\n<!-- Reviewable:end -->\r\n"},"comment":{"url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/comments/219450711","html_url":"https://github.com/dolphin-emu/dolphin/pull/3794#issuecomment-219450711","issue_url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/3794","id":219450711,"user":{"login":"RisingFog","id":2121359,"avatar_url":"https://avatars.githubusercontent.com/u/2121359?v=3","gravatar_id":"","url":"https://api.github.com/users/RisingFog","html_url":"https://github.com/RisingFog","followers_url":"https://api.github.com/users/RisingFog/followers","following_url":"https://api.github.com/users/RisingFog/following{/other_user}","gists_url":"https://api.github.com/users/RisingFog/gists{/gist_id}","starred_url":"https://api.github.com/users/RisingFog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RisingFog/subscriptions","organizations_url":"https://api.github.com/users/RisingFog/orgs","repos_url":"https://api.github.com/users/RisingFog/repos","events_url":"https://api.github.com/users/RisingFog/events{/privacy}","received_events_url":"https://api.github.com/users/RisingFog/received_events","type":"User","site_admin":false},"created_at":"2016-05-16T15:10:58Z","updated_at":"2016-05-16T15:10:58Z","body":"What's left to be done before this is ready to merge?"}}