How to check if a mutex is locked?

Hi there,

Is there a way to check if a mutex is locked?

The only way I can see how to do it at the moment is to try and lock it. If it isn’t locked I can then unlock it, and if it is locked I get a SDL_MUTEX_TIMEDOUT value back.

However, this seems like a clumsy solution.

Cheers,
Steve

Is this what you are looking for?

https://wiki.libsdl.org/SDL_TryLockMutex

Cheers,

AlvinOn 11/09/14 15:52, Starg wrote:

Hi there,

Is there a way to check if a mutex is locked?

The only way I can see how to do it at the moment is to try and lock it. If it isn’t locked I can
then unlock it, and if it is locked I get a SDL_MUTEX_TIMEDOUT value back.

However, this seems like a clumsy solution.

Cheers,
Steve

[…]

The only way I can see how to do it at the moment is to try and lock it. If it isn’t locked I can then unlock it, and if it is locked I get a SDL_MUTEX_TIMEDOUT value back.
[…]

What are you trying to achieve here? What are you planning on doing in
the case where the mutex is locked?

The problem with merely checking the status of a mutex is that you
essentially end up with useless information, because someone else
might lock that mutex the next moment. That’s why you have
non-blocking “trylock” operations in most APIs! Generally, you’ll want
to do something if you acquire the lock, in which case you want it
locked until you’re done, or you want to do something else (try a
different queue, render some more audio, render another video frame,
…) before you try again.On Thu, Sep 11, 2014 at 8:52 PM, Starg wrote:


//David Olofson - Consultant, Developer, Artist, Open Source Advocate

.— Games, examples, libraries, scripting, sound, music, graphics —.
| http://consulting.olofson.net http://olofsonarcade.com |
’---------------------------------------------------------------------’

Right, i see what you mean.

Well, in this particular case, my game saves data on exit. This is done on a separate thread. I wanted the main thread to check if the mutex was unlocked so the game can quit.

Well, in this particular case, my game saves data on exit. This is
done on a separate thread. I wanted the main thread to check if the
mutex was unlocked so the game can quit.
just grab it.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20140911/5bec964e/attachment.pgpOn Thu, 11 Sep 2014 19:44:04 +0000 “Starg” wrote:

I think what you’d want is to SDL_WaitThread() in your main thread to be
sure that all other threads are done processing. If other threads process
in a continuous loop, use a mutexed variable or a message queue to tell the
other thread to quit the loop and let the thread end.

Jonny D