[gameprogrammer] Re: variables and multithreading
- From: Roger D Vargas <luo_hei@xxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Wed, 18 Jan 2006 11:46:24 -0500
Can I consider the application main loop like a thread and use mutex
operations while running that loop?
Stephane Marchesin escribió:
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
--
Roger D. Vargas
http://dsgp.blogspot.com | Linux, programación, juegos
______________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice.yahoo.com
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- Follow-Ups:
- [gameprogrammer] Re: variables and multithreading
- From: Bob Pendleton
- References:
- [gameprogrammer] variables and multithreading
- From: Roger D Vargas
- [gameprogrammer] Re: variables and multithreading
- From: Stephane Marchesin
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
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
-- Roger D. Vargas http://dsgp.blogspot.com | Linux, programación, juegos
--------------------- To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- [gameprogrammer] Re: variables and multithreading
- From: Bob Pendleton
- [gameprogrammer] variables and multithreading
- From: Roger D Vargas
- [gameprogrammer] Re: variables and multithreading
- From: Stephane Marchesin