[gameprogrammer] Re: variables and multithreading
- From: Bob Pendleton <bob@xxxxxxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Wed, 18 Jan 2006 12:01:45 -0600
On Wed, 2006-01-18 at 11:46 -0500, Roger D Vargas wrote:
> Can I consider the application main loop like a thread and use mutex
> operations while running that loop?
The main loop is *a* thread. You have to use a mutex to control access
from *all* threads. Only one thread at a time can be allowed to access
the data. You can use a mutex per record, or a mutex for the entire set
of records. It all depends on what kind of control you need.
Bob Pendleton
>
> 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
> >
> >
> >
>
--
+--------------------------------------+
+ Bob Pendleton: writer and programmer +
+ email: Bob@xxxxxxxxxxxxx +
+ web: www.GameProgrammer.com +
+ www.Wise2Food.com +
+ nutrient info on 7,000+ common foods +
+--------------------------------------+
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- References:
- [gameprogrammer] variables and multithreading
- From: Roger D Vargas
- [gameprogrammer] Re: variables and multithreading
- From: Stephane Marchesin
- [gameprogrammer] Re: 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
- [gameprogrammer] variables and multithreading
- From: Roger D Vargas
- [gameprogrammer] Re: variables and multithreading
- From: Stephane Marchesin
- [gameprogrammer] Re: variables and multithreading
- From: Roger D Vargas