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.

This change is a pre-requisite for PR #509.