[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Thread safety in games



When writing games, there are definitely times when
a second thread saves programmer effort.
(If your level loading or unloading code is slow,
you might use a second thread to keep the network alive
or the user interface happy.)

It's very easy to shoot yourself in the foot with
threads, though.  The only really safe way to use multiple
threads is to let the various threads communicate
only in a very simple, well defined manner, usually
through a queue.  (Anything more complicated leads
to mysterious deadlocks, in my meager experience,
unless you're Linus Torvalds.  And even then, sometimes.)

http://www.humanfactor.com/gpk/ is a good example
of how to use a queue to make a multithreaded program
safe from deadlock.
- Dan
-- 
Speaking only for myself, not for my employer