Better thread support?

Hi,

currently SDL has MUTEX and semaphores for thread synchronisation.
Is it possible to have something equal to:

pthread_cond_wait
pthread_cond_signal

and pthread_try_lock ?

You need these things when you protect a thread with a mutex variable.
(normally you protect a single variable with a mutex, and not a
thread)

example:

Thread 1 runs (holds mutex A locked)
Thread 2 locks mutex B
Thread 1 polls mutex B with a try_lock (gets EBUSY)
Thread 1 release Mutex A and goes to sleep on a condition variable.
Thread 2 change a variable (he holds Mutex A and B)
Thread 2 release Mutex B
Thread 2 signals a wakeup Condition
Thread 1 graps Mutex A back and runs.

You need the trylock because this is the condition for a thread to
"sleep"
and wait for a condition. You cant do it with a real lock, because this
is
then a deadlock, you need the trylock.

Is it possible to make a workaround with semaphores?

Martin

currently SDL has MUTEX and semaphores for thread synchronisation.
Is it possible to have something equal to:

pthread_cond_wait
pthread_cond_signal

and pthread_try_lock ?

The latest CVS has the following functions in SDL_mutex.h:

extern SDL_cond * SDL_CreateCond(void);
extern void SDL_DestroyCond(SDL_cond *cond);
extern int SDL_CondSignal(SDL_cond *cond);
extern int SDL_CondBroadcast(SDL_cond *cond);
extern int SDL_CondWait(SDL_cond *cond, SDL_mutex *mut);
extern int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms);

You can thank Stephane Peter for these. :slight_smile:

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