Fix bug with stopping engine thread from the engine thread