[SDL] C++ and SDL_Thread
Scott Harper
lareon at comcast.net
Tue Jan 30 22:07:04 PST 2007
On Jan 30, 2007, at 10:34 PM, Scott Harper wrote:
> Hello,
>
> I would like to create a class which, when instantiated, owns a
> thread calling one of its member functions. Thus, I have this class
> (I've cut some parts that aren't important to save space, but they
> all work as intended, I'm just adding the threading to hopefully
> speed things up a smidgeon):
> ...snip...
> Again, I have little more than a broad idea of what's REALLY going
> on, so does anyone have any comments on this? Is this an okay way to
> handle things (cut/paste this code into a header in my project and
> utilize as is-sort of thing)? Is there anything to be done in the
> SDL codebase to make this sort of thing unnecessary? Has perhaps
> something already been done?
I also found this as a possible solution:
class CMyClass
{
public:
static int UpdateHelper(void *);
int Update();
};
int CMyClass::UpdateHelper(void *t)
{
return ((CMyClass *)t)->Update();
}
...
UpdateThread = SDL_CreateThread(UpdateHelper, this);
...
That seems cleaner to me, so I'm going to go with this for now and
change if y'all have a better suggestion.
-- Scott
More information about the SDL
mailing list