Game Development Reference
In-Depth Information
Chapter 25
Speeding Up Games with
Concurrent Programming
Processor manufacturers have hit a ceiling on the number of cycles their CPUs can execute per
second. This can be seen with modern CPUs in desktop computers, tablets, and mobile phones
where CPU speeds are rarely seen over the 2.5 Ghz mark.
CPU manufacturers have taken to adding more and more cores to their CPUs to provide more and
more performance. The Xbox One, PlayStation 4, Samsung Galaxy phones, and desktop CPUs all
have access to eight CPU cores to execute programs. This means that programmers of modern
software need to embrace multithreaded, concurrent programming if they wish their programs to
get the most out of modern computing devices and feel fluid and responsive for their users. Game
programmers have to think about concurrency even across different processors. The Xbox One and
PlayStation 4 actually have dual quad-core CPUs, audio CPUs, and GPUs all executing code at the
same time.
This chapter will introduce multicore CPU programming so that you can have a basic understanding
of how C++ allows you to execute code on multiple threads, how to ensure that those threads
share resources responsibly, and how to make sure that all of the threads are destroyed before your
program ends.
Running Text Adventure in Its Own Thread
I'm going to show you how to create a thread in this section that will execute the Game::RunGame
method. This will mean that the main game loop is running in its own execution thread and our main
function is left to carry out other tasks. Listing 25-1 shows how to create a game thread.
267
 
Search WWH ::




Custom Search