[SDL] semaphores made from mutexes?
slouken at devolution.com
Wed Apr 19 12:42:43 PDT 2000
> > > If initial_value > 1, SDL_SemPost() will (potentially) be called by a
> > > thread that has not originally locked the mutex.
> > That's okay. In fact that is the way it is supposed to work. The first
> > block on the mutex when count == 0 should block, and then any subsequent
> > post should unblock the waiting thread.
> > Am I misunderstanding you?
> I assumed that this was intentional.
> The problem is that this is not supported by POSIX and that it does not work
> with pthreads on Linux. Only the locking thread is allowed to unlock the
Ahh, yes, this is a serious flaw.
>From looking at the source to linuxthreads, it appears that fast mutexes
do not check ownership of the lock, but a comment elsewhere in the code
gives me pause:
This is safe because there are no concurrent __pthread_unlock
operations -- only the thread that locked the mutex can unlock it.
Okay, so we need a condition variable implementation
... which is often implemented by semaphores ...
A good discussion of condition variables and implementation is available
Stephane, I don't have a good solution for you right now.
-Sam Lantinga, Lead Programmer, Loki Entertainment Software
More information about the SDL