Is SDL_LockMutex recursive?

Hi,
I cannot find anything in the docs confirming that SDL_LockMutex
supports recursive locking, can someone please confirm it does?

Cheers.

I cannot find anything in the docs confirming that SDL_LockMutex
supports recursive locking, can someone please confirm it does?

It does.

Windows uses EnterCriticalSection(), which allows recursion. The pthread
implementation will do recursive mutexes if the system allows it, and
emulates them on top of non-recursive mutexes if the system does not.

The “generic” and PSP implementations are build on top of a semaphore,
and have recursion built on top of it, too.

My expectation is we’ll build any future targets in the same way (if we
ever need something other than Windows and pthreads in the future).

(I’m not sure if this was true in 1.2: there were a lot more thread
targets and I don’t know if they all supported recursion.)

–ryan.

Sounds to me like you’r after a semaphore or equivalent, not a “locked/unlocked” mutex solution for recursive locking?

No actually a recursive mutex is exactly what I need because I have a
resource than need to be accessed with a mutex, but I can’t tell exactly
which function will call which, so I just litter te code with mutex
locking and everything works.On 02/06/2014 11:04 AM, dimman wrote:

Sounds to me like you’r after a semaphore or equivalent, not a
"locked/unlocked" mutex solution for recursive locking?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I added a note to the wiki to clarify this:
https://wiki.libsdl.org/CategoryMutexOn Thu, Feb 6, 2014 at 7:10 AM, Ryan C. Gordon wrote:

I cannot find anything in the docs confirming that SDL_LockMutex

supports recursive locking, can someone please confirm it does?

It does.

Windows uses EnterCriticalSection(), which allows recursion. The pthread
implementation will do recursive mutexes if the system allows it, and
emulates them on top of non-recursive mutexes if the system does not.

The “generic” and PSP implementations are build on top of a semaphore, and
have recursion built on top of it, too.

My expectation is we’ll build any future targets in the same way (if we
ever need something other than Windows and pthreads in the future).

(I’m not sure if this was true in 1.2: there were a lot more thread
targets and I don’t know if they all supported recursion.)

–ryan.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org