Retrieving thread IDs

My program has a bunch of little threads running around, and sometimes it’s hard to tell what’s doing what. I know at least some of them are coming from SDL, such as the audio thread and the event thread.

Some languages have tricks to give a thread a name that will show up in the debugger, but to do this you need to know what thread to name. Is there some way we could get a function that provides IDs for SDL’s internally-created threads? I know on Windows, you need the ThreadID of the thread. Not sure exactly what it would take (or if this is even supported) on other platforms. But it would still be nice to have…

The SDL_Thread struct is anonymous… but you might be able to use:

http://www.libsdl.org/cgi/docwiki.cgi/SDL_ThreadID

The SDL_Thread struct is anonymous… but you might be able to use:

http://www.libsdl.org/cgi/docwiki.cgi/SDL_ThreadID

Yeah, that’s almost what I need. But SDL_ThreadID only returns the ID of the current thread. I might be able to get that to run from within the context of the event thread by posting a user event, but from the audio thread? It would take some gross hackery to pull that one off.

I’d prefer something I can call from the main thread, for example:

typedef enum
{
SDL_LIBTHREAD_EVENT = 0x00000001,
SDL_LIBTHREAD_AUDIO = 0x00000002,
//any others go here
} SDL_LibThreadType;

Uint32 SDL_LibThreadID(SDL_LibThreadType LibThread);>From: Will Langford

Subject: Re: [SDL] Retrieving thread IDs

The SDL_Thread struct is anonymous… but you might be able to use:

http://www.libsdl.org/cgi/docwiki.cgi/SDL_ThreadID

Yeah, that’s almost what I need. But SDL_ThreadID only returns the ID of
the current thread. I might be able to get that to run from within the
context of the event thread by posting a user event, but from the audio
thread? It would take some gross hackery to pull that one off.

Unless you’re on Win16 or a pre OS X Mac (any others running audio in some
sort of “raw” interrupt context?), I believe SDL_ThreadID() should work in the
audio thread as well, and probably SDL_PushEvent() too.

I’d prefer something I can call from the main thread, for example:

typedef enum
{
SDL_LIBTHREAD_EVENT = 0x00000001,
SDL_LIBTHREAD_AUDIO = 0x00000002,
//any others go here
} SDL_LibThreadType;

Uint32 SDL_LibThreadID(SDL_LibThreadType LibThread);

That would be nice, though…On Wednesday 14 April 2010, at 01.07.41, Mason Wheeler wrote:

From: Will Langford
Subject: Re: [SDL] Retrieving thread IDs


//David Olofson - Developer, Artist, Open Source Advocate

.— Games, examples, libraries, scripting, sound, music, graphics —.
| http://olofson.net http://kobodeluxe.com http://audiality.org |
| http://eel.olofson.net http://zeespace.net http://reologica.se |
’---------------------------------------------------------------------’

Yeah, that’s almost what I need. But SDL_ThreadID only returns the ID of
the current thread. I might be able to get that to run from within the
context of the event thread by posting a user event, but from the audio
thread? It would take some gross hackery to pull that one off.

Unless you’re on Win16 or a pre OS X Mac (any others running audio in some
sort of “raw” interrupt context?), I believe SDL_ThreadID() should work in the
audio thread as well, and probably SDL_PushEvent() too.

What I mean is, it’s kinda difficult to get a piece of arbitrary code to execute
from within the context of the audio thread in the first place. You can set up
callbacks to run while a sound is playing, but that’s about it.>----- Original Message ----

From: David Olofson
Subject: Re: [SDL] Retrieving thread IDs

Yeah, that’s almost what I need. But SDL_ThreadID only returns the ID
of the current thread. I might be able to get that to run from within
the context of the event thread by posting a user event, but from the
audio thread? It would take some gross hackery to pull that one off.

Unless you’re on Win16 or a pre OS X Mac (any others running audio in some
sort of “raw” interrupt context?), I believe SDL_ThreadID() should work in
the audio thread as well, and probably SDL_PushEvent() too.

What I mean is, it’s kinda difficult to get a piece of arbitrary code to
execute from within the context of the audio thread in the first place.
You can set up callbacks to run while a sound is playing, but that’s about
it.

Yes… But if you set up the audio callback to check the thread ID and send it
off first time it fires, it should be in the event queue when you look for it
later, right?

(And I think the audio should stay in the same thread as long as it’s
running… At least SDL_PauseAudio() only determines whether or not to run the
callback; audio output is always running.)On Wednesday 14 April 2010, at 01.33.18, Mason Wheeler wrote:

----- Original Message ----
From: David Olofson <@David_Olofson>
Subject: Re: [SDL] Retrieving thread IDs


//David Olofson - Developer, Artist, Open Source Advocate

.— Games, examples, libraries, scripting, sound, music, graphics —.
| http://olofson.net http://kobodeluxe.com http://audiality.org |
| http://eel.olofson.net http://zeespace.net http://reologica.se |
’---------------------------------------------------------------------’