iHaveNet.com
Video Games: Synchronization Between Threads in the Infernal Engine
Online Breaking News Headlines Single Source to Headlines Breaking News Current Events Top Stories. Find out what is happening in News & the World. Check out iHaveNet.com for the latest news & current events articles plus Movie Reviews, Wolfgang Puck Recipes, NFL Previews Analysis and Politics. Your Single Source to News Articles, Current Events & Reviews.
  • HOME
  • WORLD
    • Africa
    • Asia Pacific
    • Balkans
    • Caucasas
    • Central Asia
    • Eastern Europe
    • Europe
    • Indian Subcontinent
    • Latin America
    • Middle East
    • North Africa
    • Scandinavia
    • Southeast Asia
    • United Kingdom
    • United States
    • Argentina
    • Australia
    • Austria
    • Benelux
    • Brazil
    • Canada
    • China
    • France
    • Germany
    • Greece
    • Hungary
    • India
    • Indonesia
    • Ireland
    • Israel
    • Italy
    • Japan
    • Korea
    • Mexico
    • New Zealand
    • Pakistan
    • Philippines
    • Poland
    • Russia
    • South Africa
    • Spain
    • Taiwan
    • Turkey
    • United States
  • USA
    • ECONOMICS
    • EDUCATION
    • ENVIRONMENT
    • FOREIGN POLICY
    • POLITICS
    • OPINION
    • TRADE
    • Atlanta
    • Baltimore
    • Bay Area
    • Boston
    • Chicago
    • Cleveland
    • DC Area
    • Dallas
    • Denver
    • Detroit
    • Houston
    • Los Angeles
    • Miami
    • New York
    • Philadelphia
    • Phoenix
    • Pittsburgh
    • Portland
    • San Diego
    • Seattle
    • Silicon Valley
    • Saint Louis
    • Tampa
    • Twin Cities
  • BUSINESS
    • FEATURES
    • eBUSINESS
    • HUMAN RESOURCES
    • MANAGEMENT
    • MARKETING
    • ENTREPRENEUR
    • SMALL BUSINESS
    • STOCK MARKETS
    • Agriculture
    • Airline
    • Auto
    • Beverage
    • Biotech
    • Book
    • Broadcast
    • Cable
    • Chemical
    • Clothing
    • Construction
    • Defense
    • Durable
    • Engineering
    • Electronics
    • Firearms
    • Food
    • Gaming
    • Healthcare
    • Hospitality
    • Leisure
    • Logistics
    • Metals
    • Mining
    • Movie
    • Music
    • Newspaper
    • Nondurable
    • Oil & Gas
    • Packaging
    • Pharmaceutic
    • Plastics
    • Real Estate
    • Retail
    • Shipping
    • Sports
    • Steelmaking
    • Textiles
    • Tobacco
    • Transportation
    • Travel
    • Utilities
  • WEALTH
    • CAREERS
    • INVESTING
    • PERSONAL FINANCE
    • REAL ESTATE
    • MARKETS
    • BUSINESS
  • STOCKS
    • ECONOMY
    • EMERGING MARKETS
    • STOCKS
    • FED WATCH
    • TECH STOCKS
    • BIOTECHS
    • COMMODITIES
    • MUTUAL FUNDS / ETFs
    • MERGERS / ACQUISITIONS
    • IPOs
    • 3M (MMM)
    • AT&T (T)
    • AIG (AIG)
    • Alcoa (AA)
    • Altria (MO)
    • American Express (AXP)
    • Apple (AAPL)
    • Bank of America (BAC)
    • Boeing (BA)
    • Caterpillar (CAT)
    • Chevron (CVX)
    • Cisco (CSCO)
    • Citigroup (C)
    • Coca Cola (KO)
    • Dell (DELL)
    • DuPont (DD)
    • Eastman Kodak (EK)
    • ExxonMobil (XOM)
    • FedEx (FDX)
    • General Electric (GE)
    • General Motors (GM)
    • Google (GOOG)
    • Hewlett-Packard (HPQ)
    • Home Depot (HD)
    • Honeywell (HON)
    • IBM (IBM)
    • Intel (INTC)
    • Int'l Paper (IP)
    • JP Morgan Chase (JPM)
    • J & J (JNJ)
    • McDonalds (MCD)
    • Merck (MRK)
    • Microsoft (MSFT)
    • P & G (PG)
    • United Tech (UTX)
    • Wal-Mart (WMT)
    • Walt Disney (DIS)
  • TECH
    • ADVANCED
    • FEATURES
    • INTERNET
    • INTERNET FEATURES
    • CYBERCULTURE
    • eCOMMERCE
    • mp3
    • SECURITY
    • GAMES
    • HANDHELD
    • SOFTWARE
    • PERSONAL
    • WIRELESS
  • HEALTH
    • AGING
    • ALTERNATIVE
    • AILMENTS
    • DRUGS
    • FITNESS
    • GENETICS
    • CHILDREN'S
    • MEN'S
    • WOMEN'S
  • LIFESTYLE
    • AUTOS
    • HOBBIES
    • EDUCATION
    • FAMILY
    • FASHION
    • FOOD
    • HOME DECOR
    • RELATIONSHIPS
    • PARENTING
    • PETS
    • TRAVEL
    • WOMEN
  • ENTERTAINMENT
    • BOOKS
    • TELEVISION
    • MUSIC
    • THE ARTS
    • MOVIES
    • CULTURE
  • SPORTS
    • BASEBALL
    • BASKETBALL
    • COLLEGES
    • FOOTBALL
    • GOLF
    • HOCKEY
    • OLYMPICS
    • SOCCER
    • TENNIS
  • Subscribe to RSS Feeds EMAIL ALERT Subscriptions from iHaveNet.com RSS
    • RSS | Politics
    • RSS | Recipes
    • RSS | NFL Football
    • RSS | Movie Reviews

Synchronization Between Threads in the Infernal Engine
Mark Randel

HOME > VIDEO GAME REVIEWS

 

SocialTwist Tell-a-Friend

Thread synchronization is a complicated problem and rarely discussed in practice. We came to our own conclusions via experimentation and what worked well for us during the production of Ghostbusters.

Ghostbusters used two kinds of synchronization primitives: 'crude locks' and 'critical sections.' A crude lock is the lowest form of synchronization. It lets one thread sit in a loop until the other thread lets it continue. Here is how a simple implementation of a crude lock class could look in C++:

class CCrudeLock {

volatile long value;

public:

CCrudeLock() { value = 1; }

void lock() {

for (;;) {

if (1 == InterlockedCompareExchangeAcquire(&value,0,1)) {

return;

}

}

}

void unlock() {

value = 1;

}

};

As you can see in the lock code, if one thread tries to acquire the lock and it is busy, it will sit in a tight loop burning CPU time forever until it gets the lock. The InterlockedCompareExchangeAcquire function is an atomic function that will synchronize the access of a variable across multiple threads. In assembly language, it could look like the following:

mov ecx,dword ptr [esp+4] ; Get the address of value into ecx

mov edx,dword ptr [esp+8] ; Get "0" into edx

mov eax,dword ptr [esp+12] ; Get "1" into eax

lock cmpxchg dword ptr [ecx],edx ; Compare the value of eax with the destination, and if equal, write edx into the destination

ret 12 ; eax = return value

So the guts of the InterlockedCompareExchangeAcquire function is the 'cmpxchg' instruction with the 'lock' prefix, which preserves the order of operations so that more than one processor does not interrupt this single instruction -- it functions atomically.

On a cache coherent multiprocessor, releasing the crude lock is as simple as writing back to the memory location. If another thread is attempting to acquire the lock, the atomic interlocked function will guarantee the order of operations.

The other type of synchronization primitive we used is the standard Windows CRITICAL_SECTION structure. This structure is well documented, although the implementation may not be, so we will discuss how it might work internally. A standard critical section is similar to the crude lock, with the loop being finite: If a certain amount of loop iterations happen and it cannot acquire the lock, then yield the thread for an amount of time and start over.

class CCriticalSection {

volatile int value;

public:

CCriticalSection() { value = 1; }

void lock() {

int loopCount = 0;

for (;;) {

if (1 == InterlockedCompareExchangeAcquire(&value,0,1)) {

return;

}

loopCount++;

if (loopCount > 400) {

Yield();

loopCount = 0;

}

}

void unlock() {

value = 1;

}

};

Note that the loopCount value is local to the lock function, so that more than two threads can attempt to access our critical section at any one time.

When is it appropriate to use a crude lock instead of a critical section?

Take a four-core processor with two threads each, or hyperthreading. Although there are two sets of register contexts for each thread, there is only one execution unit. So if thread one is blocked on a core, thread two can start to execute if possible. If two code threads try to acquire the lock in a crude lock and they are both executing on the same processor, you can have a live lock situation occur.

Ghostbusters was a multiplatform title, with the PC, Xbox 360 and PlayStation 3 supported. For the PC and PS3, we used critical sections to synchronize code. The PC could be hyperthreaded, and the PS3 is hyperthreaded. Although the Xbox 360 is hyperthreaded, you are able to select which thread on which core you can run your code on, so in the end we were able to use the lighter crude lock for thread synchronization because we could guarantee what hardware threads our game would run on.

Note that whenever you have a crude lock or critical section in your code, you need to guarantee that you will be accessing that resource for only a very short amount of time. Staying inside of a critical section of your code for a long time will have negative effects on performance.

 

Mark Randel is the president and chief technology officer of Terminal Reality Inc., developer of Ghostbusters: The Video Game

 

Videogaming & Video Game Reviews

  • 'Portal 2'
  • Saving the Universe One LEGO Brick at a Time
  • Synchronization Between Threads in the Infernal Engine
  • Thought Leaders: Eleanor Wynn
  • The Art of War: Shogun 2
  • Solid-state Drives Revolutionize Gaming
  • War Production: Chatting With Frank Pearce of Blizzard
  • 'Ghostbusters: Sanctum of Slime'
  • Darkspore Creatures Come to Life
  • Finding the Next Challenge in Visual Computing
  • 'The Sims: Medieval'
  • The Future of PC Gaming? A Personal Viewpoint
  • Explosion of Creativity: Power of Online Communities
  • 'Homefront'
  • Game Optimization for Modern Hardware
  • 'PixelJunk Shooter 2: The Belly of the Beast'
  • Pixels and Sand
  • Sneak Peek at DC Universe Online With Chris Cao
  • Thought Leaders: Orion Granatir
  • Combat Duality in 'Dragon Age II'
  • 'Jikandia: The Timeless Land'
  • Exclusive Look at Homefront
  • GDC 2011: Sneak Peek of Battlefield 3
  • Talking Portal 2 With Valve Software's Erik Wolpaw
  • Nathan Camarillo of Crytek Talks Crysis 2 and CryEngine 3
  • 'Two Worlds II'
  • 'Dungeons'
  • Peter Molyneux Talks Fable III and Commitment to PC Gaming
  • There's an App for That Game
  • Talking Tech Tactics With Football Manager 2011
  • 'Kingdom Hearts Re:coded'
  • 'Dead Space 2'
  • 2K Sports Announces 'NHL 2K11' for Apple iPad
  • 'Dead Space' for iOS
  • Why are Video Games for Girls so Lame?
  • The Muddy Beauty of DiRT 2
  • The Reality of Indie Game Development
  • Using Artificial Intelligence in Game Development
  • Top 10 Most Anticipated Video Games of 2011
  • Need for Speed Drives Back to Roots
  • Developing and Optimizing Games for Netbooks
  • 'Bejeweled 3'
  • Rolling Thunder, Analytics and Performance Drive Need for Speed World
  • Who You Gonna Call? Ghostbusters Challenges
  • Dude! Who Killed My First-person Shooter?
  • Racing to the Finish Line: Chris Southall Talks Total War and Sonic
  • The Force Remains Strong with LEGO Star Wars III: The Clone Wars
  • Unreal Engine 3 Brings Chadam to Life on Web Video
  • 'Pac-Man Championship Edition DX'
  • 'Infinity Blade'
  • TRON: Evolution -- Game Developers Go Hollywood
  • EA Sports Moves Graphics-rich Gaming Online
  • Humble Opinions: From The Sims to Indie Games
  • Meet Mr. Industrial: Justin Lassen's Music Machine
  • 'Assassin's Creed: Brotherhood'
  • 'Mario Vs. Donkey Kong: Mini-Land Mayhem'
  • 'Time Crisis Razing Storm'
  • 'Arcania: Gothic 4'
  • 'Disney Epic Mickey'
  • 'Final Fantasy: The 4 Heroes of Light'
  • 'Ace Combat: Air Assault'
  • 'Game Dev. Story'
  • Epic Games Unveils 'Gears of War 3' Multiplayer Details
  • 'Castlevania: Lords of Shadow'
  • 'Sonic the Hedgehog 4: Episode 1'
  • 'Amnesia: The Dark Descent'
  • 'Enslaved: Odyssey to the West'
  • 'Valkyria Chronicles II'
  • 'Dead Rising 2'
  • 'Kingdom Hearts Birth by Sleep'
  • 'Halo: Reach'
  • 'Mafia II'
  • 'Scott Pilgrim' vs. Its Video Game References

 

Video Games: Synchronization Between Threads in the Infernal Engine

Copyright © 2011 Studio One Networks. All rights reserved.

 

Recommend

Brought to you by Visual Adrenaline

This editorial content is brought to you by webroot

Search Powered By Google

Google Search   

Your Favorite Comic Strips Online

Daily Comics & Your Favorite Comic Strips Online

Your favorite comics strips Animal Crackers, Annie, Bound & Gagged, Brenda Starr, Brewster Rockit: Space Guy, Broom-Hilda, Dick Tracy, Gasoline Alley, Gil Thorp, Housebroken, Loose Parts, The Middletons, Pink Panther, Raising Hector, Sylvia, 9 to 5, Bliss, Bottom Liners, Love Is..., Pluggers all online at ComicStripNation.com

ADVERTISEMENT

Advertisement

ADVERTISEMENT

Advertisement

Your Ad Here
Your Ad Here
  • HOME
  • WORLD
  • USA
  • BUSINESS
  • WEALTH
  • STOCKS
  • TECH
  • HEALTH
  • LIFESTYLE
  • ENTERTAINMENT
  • SPORTS

Video Games: 'The Saboteur' - Xbox 360

 

  • Services:
  • RSS Feeds
  • Shopping
  • Email Alerts
  • Site Map
  • Privacy