[gameprogrammer] Re: variables and multithreading
- From: Stephane Marchesin <stephane.marchesin@xxxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Wed, 18 Jan 2006 16:14:29 +0100
Roger D Vargas wrote:
Im writing a multithreaded server and I have reached the point where I
have to access the array containing the players data from the main
loop. Should I use some variable to mark if a record is being modified
by network thread?
Well, you should use more than a variable, you should use a mutex or a
semaphore (these are special variable s that ensures mutual exclusion
between different threads). If you don't, things will go bad sooner or
later. Even if the network thread is the only one writing to the player
data, it might be preempted in the middle of an update, and the main
thread will read inconsistent data.
I suggest you read a tutorial on mutexes and semaphores (the theory
behind all mutexes/semaphores implementation is the same, only the
function names change). Or you could look at SDL which implements this
stuff, the functions are quite simple and highly portable :
http://www.libsdl.org/cgi/docwiki.cgi/SDL_20API
Stephane
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- Follow-Ups:
- [gameprogrammer] Re: variables and multithreading
- From: Roger D Vargas
- References:
- [gameprogrammer] variables and multithreading
- From: Roger D Vargas
Other related posts:
- » [gameprogrammer] variables and multithreading
- » [gameprogrammer] Re: variables and multithreading
- » [gameprogrammer] Re: variables and multithreading
- » [gameprogrammer] Re: variables and multithreading
- » [gameprogrammer] Re: variables and multithreading
- » [gameprogrammer] Re: variables and multithreading
- » [gameprogrammer] Re: variables and multithreading
- » [gameprogrammer] Re: variables and multithreading
- » [gameprogrammer] Re: variables and multithreading
--------------------- To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- [gameprogrammer] Re: variables and multithreading
- From: Roger D Vargas
- [gameprogrammer] variables and multithreading
- From: Roger D Vargas