[SDL] How to check if a mutex is locked?

David Olofson david at olofson.net
Thu Sep 11 12:30:51 PDT 2014


On Thu, Sep 11, 2014 at 8:52 PM, Starg <steve at coldbeamgames.com> wrote:
[...]
> 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.


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

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



More information about the SDL mailing list