Make the emulation stop asynchronous to prevent deadlocks.

This PR moves the synchronisation to the last possible moment when we're already certain that the EmuThread has been shut down.

It fixes a potential deadlock where the VideoBackend is waiting for the GUI thread and vice versa. This deadlock seems to only be triggered by exclusive fullscreen, thus this PR is required for PR #506.

This PR has the potential to expose race conditions in code that does not properly check the emulation state so it should be tested thoroughly.
Anyway, I'd personally prefer something like "Before closing the window we need to shut down the emulation core. We'll try to close this window again once that is done." (point being that the beginning of this comment sums up the situation under which this code is called)