Semaphores on top of SDL Mutexes... HELP!

I spent one day so far trying to implement a simple counting
semaphore on top of SDL mutexes (trying to do so under Win95).

I am about to start smashing things in frustration. My code
does not work because of one feature: a mutex lock is owned
by the thread that calls SDL_mutexP( ), and the next attempt
to lock the same mutex from the same thread won’t block this
thread (which is how it’s supposed to be, I guess).

My question is… is it possible to add functions like
SDL_SuspendThread( )
and SDL_ResumeThread( ) to make a thread sleep and wake it up,
respectively? If I had them, implementing things like counting
semaphores would be very easy (along with all other concurrent
structures).

(BTW I really don’t want to start using Win32-specific code
since I’m planning to run this code under Linux eventually).

Thanks,
MC

I spent one day so far trying to implement a simple counting
semaphore on top of SDL mutexes (trying to do so under Win95).

You can’t implement semaphores with mutexes, because mutexes by
definition can not be unlocked by other threads, while semaphores
can.

Try the new semaphore code in SDL 1.1.5 (in CVS)
http://www.libsdl.org/cvs.html
http://sdldoc.sourceforge.net/current/sdlcreatesemaphore.html

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

You can’t implement semaphores with mutexes, because mutexes by
definition can not be unlocked by other threads, while semaphores
can.

Er… ok, thanks for making my brain less foggy. :slight_smile:
So, if I cannot implement semaphores this way, is there an existing
(and hopefully working) implementation of semaphores in SDL?

And if it’s there (and I am not looking in the right place), where is
it and where can I get docs on it?

Thanks,
M.C.

So, if I cannot implement semaphores this way, is there an existing
(and hopefully working) implementation of semaphores in SDL?

And if it’s there (and I am not looking in the right place), where is
it and where can I get docs on it?

Sam said there was in his message. ;>

Sam said:

Try the new semaphore code in SDL 1.1.5 (in CVS)

You can download that source from

http://www.libsdl.org/cvs.html

You can find docs atFrom: merlecorey@crosswinds.net
Subject: Re: [SDL] Semaphores on top of SDL Mutexes… HELP!!!
Date: Sat, 23 Sep 2000 21:40:15 -0500

http://sdldoc.sourceforge.net/current/sdlcreatesemaphore.html

And if it’s there (and I am not looking in the right place), where is
it and where can I get docs on it?

Sam said there was in his message. ;>

Sam said:

Try the new semaphore code in SDL 1.1.5 (in CVS)

You can download that source from

http://www.libsdl.org/cvs.html

You can find docs at

http://sdldoc.sourceforge.net/current/sdlcreatesemaphore.html

Blushes

Thank you. :slight_smile: That’s what one gets after one full day of unproductive
attempts to build something that cannot be built at all.

Anyway, I already got 1.1.5, VC++ 6.0 compiles it with warnings and
builds with fatal errors… sigh

BTW, just to make sure I am not writing something that’s already
written: is there anything in SDL resembling shared queues and priority
queues? And if not, does anybody think SDL could use these?

Thanks,
M.C.