Implementing the game loop with a thread