Multi-Threading with SDL

Under SDL how would I create a system where Function A sets a flag
"resetRequest" in some common struct, and waits for Function B, which
runs in a different thread to set a flag “resetDone”. I’m trying to use
mutexes now, but I can’t seem to figure it out. If I have two mutexes
resReq and resDone and Function A locks resReq, then Function B will
fail when it tries to lock resReq, but this means it will actively have
to watch for this, and if it tries to lock when resReq is not locked, it
will get the lock and Function A will not be able to lock…anyway, is
there some cross-platform, fast, interthread communication method
available?

Stuart–
This signature has been infected by the signature virus.
Please help me spread and copy me to your .signature.

Under SDL how would I create a system where Function A sets a flag
"resetRequest" in some common struct, and waits for Function B, which
runs in a different thread to set a flag “resetDone”. I’m trying to use
mutexes now, but I can’t seem to figure it out. If I have two mutexes
resReq and resDone and Function A locks resReq, then Function B will
fail when it tries to lock resReq, but this means it will actively have
to watch for this, and if it tries to lock when resReq is not locked, it
will get the lock and Function A will not be able to lock…anyway, is
there some cross-platform, fast, interthread communication method
available?

Hmmm…that’s very odd. I would have though condition variables would
have already been included in SDL but it seems they have not. What you
are describing sounds just like a usage of a condition/mutex pair.

Essentially you lock the mutex then wait on the condition. The wait on
the condition actually unlocks the mutex. When someone else wants to
notify you things are done they can notify you via the condition variable.

Is there any work being done in this area or, since I know a good bit
about POSIX threads, might there be some way I can add value to SDL in
this way? (Okay, this last part wasn’t directed back at you, Stuart, but
I gather you figured that out.)

Paul Braman
@Paul_BramanOn Mon, 1 Nov 1999, Stuart Anderson wrote:

Stuart Anderson wrote:

Under SDL how would I create a system where Function A sets a flag
"resetRequest" in some common struct, and waits for Function B, which
runs in a different thread to set a flag “resetDone”. I’m trying to use
mutexes now, but I can’t seem to figure it out. If I have two mutexes
resReq and resDone and Function A locks resReq, then Function B will
fail when it tries to lock resReq, but this means it will actively have
to watch for this, and if it tries to lock when resReq is not locked, it
will get the lock and Function A will not be able to lock…anyway, is
there some cross-platform, fast, interthread communication method
available?

Read any good OS theory book, so you can figure out how the semaphores
work and how to use them. There is a wrapper in SDL for semaphores. A
good introduction that explains the justification and usage of
semaphores (as well as a lot of other operating system design issues) is
"Operating Systems: Design and Implementation," by Andrew S. Tanenbaum
(yes, the same one who wrote Linux’s early ancestor Minix; he describes
this in the book as well).–

| Rafael R. Sevilla @Rafael_R_Sevilla |
| Instrumentation, Robotics, and Control Laboratory |

College of Engineering, University of the Philippines, Diliman