Game Development Reference
In-Depth Information
Figure 20.2
The Threads window in Visual Studio.
When you have multiple threads running in your game, you can debug each of them,
to a point. In Visual Studio, you can show the Threads window by selecting
Debug
Threads from the main menu (see Figure 20.2).
When you hit a breakpoint, all threads stop execution. If you double-click on a row
in the Threads window, you will see where execution has stopped in that thread. You
can easily set breakpoints in the thread procedure, but if you run multiple threads
using the same procedure, you can never tell which thread will hit the breakpoint
first! It can become a little confusing.
Creating a thread is pretty trivial, as you have seen. Getting these threads to work
together and not wipe out the results of other threads working on the same memory
is a little harder.
Window
Process Synchronization
There
s really no use in having threads without having some way to manage their
access to memory. In the early days of computing, programmers tried to solve this
with algorithms and logic. When I was in college, one of my favorite instructors,
Dr. Rusinkiewicz, had a ridiculous story he told to show us how these engineers
tried to create a heuristic to handle this problem.
Imagine two railways that share a tunnel in the Andes Mountains in South America.
One railway runs in Bolivia, and the other runs in neighboring Peru. The tunnel was
filled with curves, and it was impossible for either engineer to see an oncoming train
in time to stop. But both governments agreed that the trains were never in the tunnel
long enough for there to be any real risk, so they allowed the trains to run. For a few
months, nothing bad happened, but one day the trains crashed head-on in the tun-
nel. The governments of the two countries agreed that what they were doing wasn
'
'
t
safe, and something must be done.
 
 
 
Search WWH ::




Custom Search