SDLThreads: Locking more than one mutex at once?

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

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._________________________________________________________________
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

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. :slight_smile:

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.On Thu, 2003-07-03 at 06:57, Drinkin Park wrote:


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 wrote:>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. :slight_smile:

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.

To do this I would recommend phased locking in your code. Assign
weights to the different mutexes, and enforce a software policy that
demands higher valued semaphores be locked before lower valued ones. On
the flip side, lower valued semaphores must be released before higher
valued ones are released. This prevents deadlocking.

Message: 29Subject: Re: [SDL] SDLThreads: Locking more than one mutex at once?
From: bob@pendleton.com (Bob Pendleton)
To: SDL Mailing List
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. :slight_smile:

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. :frowning: 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

Message: 29
Organization:

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. :slight_smile:

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. :frowning: 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/sdlOn Thu, 2003-07-03 at 21:43, Drinkin Park wrote:
Subject: Re: [SDL] SDLThreads: Locking more than one mutex at once?
From: Bob Pendleton <@Bob_Pendleton>
To: SDL Mailing List
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:

±----------------------------------+

Message: 29
Organization:

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. :slight_smile:

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…

It is my experience that having a thread/object is not a good idea. It
is very operating system dependent and even dependent on what version of
the OS you are using. On many systems the object threads will never run.
Having a thread/object does not allow you to ensure that each object is
updated when you expect it to be. And, it makes keeping track of time
with in the game difficult, the current time is different for each
object because it depends on when the thread last ran.

	Bob PendletonOn Thu, 2003-07-03 at 21:43, Drinkin Park wrote:

Subject: Re: [SDL] SDLThreads: Locking more than one mutex at once?
From: Bob Pendleton <@Bob_Pendleton>
To: SDL Mailing List
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:

“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. :frowning: 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

±----------------------------------+