SDL Thread Support and MacOS

My programming team has been making heavy use of OpenGL and SDL in the
development of a hybrid-3D adventure game engine, and I’ve recently been
researching multi-threading function in the interest of better implementing
concurrent component execution (rendering system, audio engine, data host,
etc.). We had been focusing on a traditional game-loop sort of structure,
but determined that threading each component would decrease latency
dramatically, esp. with some of the heavy decoding tasks involved.

With our cross-platform initiative in mind, I was troubled to find that SDL

thread support is exclusive of the MacOS platform, though the reasoning
there is certainly sound. We have been planning throughout the course of
development to come at the Mac port from a Unix angle, in light of MacOS
10’s NeXTStep/Unix foundation. Seeing as Linux (one of our target platforms)
and Unix do support preemptive threads, wouldn’t it be possible to make use
of this in the SDL library, even if MacOS <9 would be out of the picture?

Something to consider.

Cordially,
"TrueFireTony"
www.Asynchrony.com

With our cross-platform initiative in mind, I was troubled to find that SDL
thread support is exclusive of the MacOS platform, though the reasoning
there is certainly sound. We have been planning throughout the course of
development to come at the Mac port from a Unix angle, in light of MacOS
10’s NeXTStep/Unix foundation. Seeing as Linux (one of our target platforms)
and Unix do support preemptive threads, wouldn’t it be possible to make use
of this in the SDL library, even if MacOS <9 would be out of the picture?

Threads work on MacOS X with SDL. There is no support for threads in MacOS
9, SDL or otherwise.

Here’s a brief test program that works on MacOS X, compiled with:

gcc -o ./test ./test.c sdl-config --cflags sdl-config --libs
(Obviously, this isn’t for Project Builder)

/* test.c … */

#include <stdio.h>
#include “SDL.h”
#include “SDL_thread.h”

static int threadFunc(void *arg)
{
SDL_Delay(3000);
printf(“This text printed from a thread.\n”);
return(42);
}

int main(int argc, char **argv)
{
SDL_Thread *thread;
int val = 0;
SDL_Init(SDL_INIT_VIDEO);
thread = SDL_CreateThread(threadFunc, NULL);
if (thread == NULL)
{
printf(“SDL_CreateThread() failed: %s\n”, SDL_GetError());
return(1);
}
printf(“thread spun.\n”);

SDL_WaitThread(thread, &val);
printf("thread terminated, returned %d.\n", val);
SDL_Quit();
return(0);

}

/* end of test.c … */

–ryan.

Message: 2

With our cross-platform initiative in mind, I was troubled to find
that SDL
thread support is exclusive of the MacOS platform, though the
reasoning
there is certainly sound. We have been planning throughout the course
of
development to come at the Mac port from a Unix angle, in light of
MacOS
10’s NeXTStep/Unix foundation. Seeing as Linux (one of our target
platforms)
and Unix do support preemptive threads, wouldn’t it be possible to
make use
of this in the SDL library, even if MacOS <9 would be out of the
picture?

Threads work on MacOS X with SDL. There is no support for threads in
MacOS
9, SDL or otherwise.

Actually, 9 has a (preemptive) thread API but you can only use threads
in code that absolutely does not call any Toolbox stuff. Since almost
all of Mac OS 9 is not thread-safe, threads are only useful for
data-crunching tasks (Photoshop uses them extensively). There was an
attempt to implemented threads in Mac OS 9 (knowing all the limitations
involved, of course) but that was never finished. I have the code
somewhere, if you care to take a stab at it.

There are ways in Mac OS 9 to do many different (normally)
multi-threaded tasks (like streaming data from disk), in a non-threaded
way (and threaded way too). But those methods are not portable at all
and don’t mesh well with a generic thread model like SDL’s.On Thursday, June 19, 2003, at 03:01 PM, sdl-request at libsdl.org wrote:

Date: Wed, 18 Jun 2003 21:12:13 -0400 (EDT)
From: “Ryan C. Gordon”
To: “sdl at libsdl.org
Subject: Re: [SDL] SDL Thread Support and MacOS
Reply-To: sdl at libsdl.org