520 likes | 720 Views
Multi-Threading and Load Balancing. Compiled by Paul TaylorCSE3AGR Stolen mainly from Orion Granatir http://www.gamasutra.com/php-bin/article_display.php?story=4006. What changed?. Single Thread Computer games have been used since day 0 The person to blame is Gordon Moore*
E N D
Multi-Threading and Load Balancing Compiled by Paul TaylorCSE3AGR Stolen mainly from Orion Granatir http://www.gamasutra.com/php-bin/article_display.php?story=4006
What changed? • Single Thread Computer games have been used since day 0 • The person to blame is Gordon Moore* * Not really it just feels good to blame someone!
Moore’s Law • The Complexity of IC’s will go up exponentially • We mutilated this into CPU speed will increase expo. • This all F*#ked up a few years ago when we started pushing the boundaries of transistor miniaturisation • To keep the processing increase we went with Multi core processors • http://en.wikipedia.org/wiki/File:Transistor_Count_and_Moore%27s_Law_-_2008.svg
It all goes bad.... • http://www.gamasutra.com/php-bin/article_display.php?story=4006
Multi-Core and Threading • http://www.gamasutra.com/php-bin/article_display.php?story=4006
Network Assimilation • http://www.gamasutra.com/php-bin/article_display.php?story=4006
The first crappy threading code you’ll see CATCTATCATTCTATCTACTATCATCTACTATCTACTATCTACTCTTACTCAT
That was a better Threading ModelBut still not good enough for today's machines
This is what Thread Locking is for Now how do we go about locking them??
Option 1: Critical Sections • When one thread enters the critical section, the others will have to wait......
Critical Sections • And wait....
Option1: Critical Sections THE RULES • Keep them small!!! • A lot of CPU time can be wasted waiting.... And waiting...
Mutexs and Semaphores • A Semaphore is like using Multiple tokens (it retains a count) • Critical Sections are fastest, but limited to one process • Mutexs are slower, but globally accessible • Semaphores are great for things like allocating your memory buffers
Atomic Operations • http://www.breadonthewaters.com/add/0888_nuclear_explosion_large_clipart.jpg
Atomic Operations 5 + 1 + 1 + 1 = 8
Atomic Operations 5 + 1 + 1 + 1 = 6!!
Atomic Operations • This is why we need atomic operations
Atomic Operations • This is why we need atomic operations
ThreadingNightmares http://ioconnor.files.wordpress.com/2009/09/danger1.jpg
Race Conditions • The ‘race’ is a term for when your code expects threads to return in order, and they don’t!!!
Network Code Example Issues • The Main thread would then need to wait for all Network threads to finish before it resets the NetworkUpdateEvent and continues • How would you solve this issue?