Threading in SDL

As I gather, it seems that some parts of the SDL use threading
internally, am I right?

The sound part I think, seemed to use threads last I checked (a while
ago), is there a way to do everything synchronously, as to avoid useless
context switching (I already feel I’m up to there in context switching
between my game and my X server without needing context switching for
something that can be done without).–
Pierre Phaneuf
Ludus Design, http://ludusdesign.com/
“First they ignore you. Then they laugh at you.
Then they fight you. Then you win.” – Gandhi

Pierre Phaneuf wrote:

As I gather, it seems that some parts of the SDL use threading
internally, am I right?

On Linux and Win32, just the audio uses threads internally.

The sound part I think, seemed to use threads last I checked (a while
ago), is there a way to do everything synchronously, as to avoid useless
context switching (I already feel I’m up to there in context switching
between my game and my X server without needing context switching for
something that can be done without).

It has been my experience that games get much better audio performance
with the threading model, especially with the newer kernels and their
improved scheduling.

The code is set up so that the audio thread wakes up only when the audio
device needs data.

So, to answer your question, no there is no way to do everything
synchronously, and you shouldn’t need to. :)–
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Sam Lantinga wrote:

As I gather, it seems that some parts of the SDL use threading
internally, am I right?

On Linux and Win32, just the audio uses threads internally.

On Win32? Only with the DIB driver, right?

It has been my experience that games get much better audio performance
with the threading model, especially with the newer kernels and their
improved scheduling.

Strange, Zoid was saying otherwise a while ago… Quake used to be
threaded, but he removed all trace of it (in Quake2 I think)…

The code is set up so that the audio thread wakes up only when the audio
device needs data.

That helps a lot. This isn’t as bad as it could be, but I’ve had thread
inflict much more pain on me than they were ever helpful, so… :slight_smile:

How about communication from the main program to the thread? There is a
few shared structures being the communication link between the two? This
is much better than the fork most people are doing in any case…

Quadra does synchroneous sound, just like Quake.

So, to answer your question, no there is no way to do everything
synchronously, and you shouldn’t need to. :slight_smile:

There is always a way… This might be opening the device myself tho!
Which isn’t so good…

Myself, I actually use a poll() to block on the X stream, the sound
device and a few network sockets with a timeout appropriate to bring me
to the next timer event.

The most funny thing is that I am forced to fork/thread to do DNS
requests, because there is no non-blocking gethostbyname()! Hehehe! I
fork and return the answer on a pipe which is on the poll(), so it isn’t
too bad either…–
Pierre Phaneuf
Ludus Design, http://ludusdesign.com/
“First they ignore you. Then they laugh at you.
Then they fight you. Then you win.” – Gandhi