Threads and Concurrent Programming
Threads may be seen as methods that execute at "the same time" as other methods. Normally, we think sequentially when writing a computer program. From this perspective, only one thing executes at a time. However, with today's multi-core processors, it is possible to literally have several things going on at the very same time while sharing the same memory. There are lots of ways that this is done in the real world, and this chapter goes over them in a way that you can apply to your own projects.
14.7 CASE STUDY: The Game of Pong
The game of Pong was one of the first computer video games and was all
the rage in the 1970s. The game consists of a ball that moves horizontally
and vertically within a rectangular region, and a single paddle, which is
located at the right edge of the region that can be moved up and down by
the user. When the ball hits the top, left, or bottom walls or the paddle,
it bounces off in the opposite direction. If the ball misses the paddle, it
passes through the right wall and re-emerges at the left wall. Each time
the ball bounces off a wall or paddle, it emits a pong sound.