In this new Intel-sponsored feature, part of
the Visual Computing section of Gamasutra, former Insomniac and current Intel staffer Orion Granatir
introduces threading by comparing it to networking in games.
Why thread? Amid adorable illustrations of cats and monsters, Granatir explains:
In the past, CPUs saw consistent performance gains because of the increases in frequency. In modern microprocessors, however, this frequency gain is marginal, and most performance benefits come from an increased number of cores.
Having more cores means the CPU can do more things at the same time. To maximize performance and features, an application needs to fully utilize the CPU -- and that means threading!
The feature also covers common pitfalls in threading, two of the most common of which are deadlocks and race conditions. On deadlocks, Granatir explains:
A deadlock happens when two or more threads are waiting on resources that are dependent on each other. Here is an example in which two threads want to do something that requires two mutexes.
In this example, one mutex might be protecting network access and the other might be protecting a log file. If both threads want to read data from the network and log it to a protected file, they need to grab both mutexes.
If one thread gets Mutex0 and the other one gets Mutex1, both don't have the required mutex to continue. This situation is bad; nothing can happen because neither thread has both mutexes. Worse yet, they will sleep waiting for each other and never wake up.
You can now
read the full (illustrated!) feature on threading at
the Visual Computing section of Gamasutra (no registration required, please feel free to link to this feature from other websites).