🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

SDL threads

Started by
10 comments, last by Squirm 19 years, 11 months ago
are SDL threads implemented as kernel recognized threads or are they a usermode thread library? Thanks in advance.

-potential energy is easily made kinetic-

Advertisement
Quote: Original post by Infinisearch
are SDL threads implemented as kernel recognized threads or are they a usermode thread library?

They are true threads. Under Linux, for example, they are an abstracted form of pthreads.

~phil
~phil
Quote: Original post by JonnyQuest

They are true threads. Under Linux, for example, they are an abstracted form of pthreads.

~phil


Uh aren't pthreads a usermode thread library? If that is correct, does anyone know if it is implemented the same way in windows?

-potential energy is easily made kinetic-

Quote: Original post by Infinisearch
Uh aren't pthreads a usermode thread library? If that is correct, does anyone know if it is implemented the same way in windows?


Quick look at the source code:

int SDL_SYS_CreateThread(SDL_Thread *thread, void *args){	DWORD  threadnum;	thread->handle = CreateThread(NULL, 0, RunThread, args, 0, &threadnum);	if (thread->handle == NULL) {		SDL_SetError("Not enough resources to create thread");		return(-1);	}	return(0);}


SDL uses the normal Windows thread library under Win32.
[teamonkey] [blog] [tinyminions]
Thanks teamonkey I had downloaded the source package yesterday to take a look but hadn't got around to it just yet, I'll take a closer look later in the day. Basically I just wanted to know if SDL instances more than one "kernel supported thread" and then muxes all the user threads on top?

-potential energy is easily made kinetic-

Quote: Original post by Infinisearch
Uh aren't pthreads a usermode thread library? If that is correct, does anyone know if it is implemented the same way in windows?

Right, I've now checked the source, and it appears the Linux version is based around clone(), i.e. LinuxThreads, which are a kernel-mode implementation of pthreads, as far as I understand. SDL on most other unices basically just uses pthreads.

The code is a bit confusing as the src/thread/linux directory doesn't only contain linux-specific code, which is a bit annoying.

For more info on threads in Linux, try this article.

~phil
~phil
Thanks for that link JohnnyQuest good read on the evolution/future of linux threading standards. BTW you didn't have to look through the source, I was going to eventually.=) Anyhow now i'm looking at SDL's events subsystem and how thread safe it is.

-potential energy is easily made kinetic-

Quote: Original post by Infinisearch
Anyhow now i'm looking at SDL's events subsystem and how thread safe it is.


Yeah, SDL's threads and events subsystems are great aren't they? You might like to take a look at this though. I don't know it it will make a difference to you or not, but it's quite interesting.
[teamonkey] [blog] [tinyminions]
Thanks teamonkey, i'd read that article a yesterday or the day before, and it was a nice read. However i'm suprised there wasn't a construct to support multiple event queues and distribute incoming events to said queues based on a type field. It would have also been nice to have threads to be able to wait on specific queues.

-potential energy is easily made kinetic-

boost (http://www.boost.org) has a rather nice set of cross platform thread routines and could be worth a look too.

This topic is closed to new replies.

Advertisement