How to check if a mutex is locked? |
How to check if a mutex is locked? |
Alvin Beach
Guest
|
On 11/09/14 15:52, Starg wrote:
Is this what you are looking for? https://wiki.libsdl.org/SDL_TryLockMutex Cheers, Alvin _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||
|
How to check if a mutex is locked? |
David Olofson
Guest
|
On Thu, Sep 11, 2014 at 8:52 PM, Starg wrote:
[...]
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 | '---------------------------------------------------------------------' _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||
|
Starg
|
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. |
|||||||||||
|
How to check if a mutex is locked? |
Jonny D
|
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 |
|||||||||||
|