[SDL] SDLThreads: Locking more than one mutex at once?
Bob Pendleton
bob at pendleton.com
Sat Jul 5 09:55:00 PDT 2003
On Thu, 2003-07-03 at 21:43, Drinkin Park wrote:
> Message: 29
> Subject: Re: [SDL] SDLThreads: Locking more than one mutex at once?
> From: Bob Pendleton <bob at pendleton.com>
> To: SDL Mailing List <sdl at libsdl.org>
> Organization:
> Date: 03 Jul 2003 11:28:22 -0500
> Reply-To: sdl at libsdl.org
>
> On Thu, 2003-07-03 at 06:57, Drinkin Park wrote:
> >Hi,
> >
> >I am currently coding a game for a short project, which I will not bore
> >anybody with the details of.
> >
> >What I am trying to do, is to write something like this -
> >
> > SDL_LockMutex(mutex1); SDL_LockMutex(mutex2);
> >
> >so that two mutexes are waited on, and only once both are unlocked, then
> >the mutexes are locked again and thread continues
>
> Those statements do not cause your program to wait for both mutices. It
> cause you program to wait for muxtex1. Then after mutex1 is locked it
> waits for mutex2. It is not possible in SDL to wait for more than one
> mutex at a time.
>
> >
> >But I know that this line will not have exactly the desired function, as
> >mutex1 may be locked unnecessarily in this instance.
> >
> >Is there anything I can do to get the functionality I am after? Any help is
> >appreciated.
>
> You didn't actually say what your desired functionality is. :-)
>
> I don't see how it can ever be unnecessary to lock both mutices. If each
> mutex controls access to a single shared resource, and you have to touch
> both resources to perform an operation, then you have to lock both
> mutices before you can touch the resources. The mutex is the only way
> you have to make sure that you can safely access the resource it
> controls.
>
> -------------------
>
> I guess that I should clarify what I need this functionality for.
>
> I am writing a simple game at the moment, and that piece of code is in the
> thread that detects collisions. It must have the mutices on both the game
> objects that it is checking before it can check if the two objects collide.
> mutex1 and mutex2 are of course the mutices on the game objects...
>
> "Those statements do not cause your program to wait for both mutices. It
> cause you program to wait for muxtex1. Then after mutex1 is locked it
> waits for mutex2."
>
> I realised that this was the case, actually.
>
> "It is not possible in SDL to wait for more than one
> mutex at a time. "
>
> That's exactly what I didn't want to hear. :( I suppose that I will just
> have to accept that mutex1 will be locked unnecessarily at times.
>
> Thanks for your help anyway.
>
> _________________________________________________________________
> Hot chart ringtones and polyphonics. Go to
> http://ninemsn.com.au/share/redir/adTrack.asp?mode=click&clientID=174&referral=Hotmail_taglines_plain&URL=http://ninemsn.com.au/mobilemania/default.asp
>
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
--
+-----------------------------------+
+ Bob Pendleton: independent writer +
+ and programmer. +
+ email: Bob at Pendleton.com +
+ web: www.GameProgrammer.com +
+-----------------------------------+
More information about the SDL
mailing list