[SDL] how to detect if a thread is still running

Neil Bradley nb at synthcom.com
Tue Jul 23 14:20:01 PDT 2002


> For a mutex-less exit status, the code should look
> something like this:
> bool IsCalculateThreadAboutToExit = true;
> int StartCalculateThread(void *)
> {
>   uint i;
>   for(i=0; i<1000000; i++)
>   {
>     /* Calculate Stuff */
>   }
>   /* I'm about to exit: tell the world! */
>   IsCalculateThreadAboutToExit = true;
> }
>
> void LaunchCalculateThread()
> {
>   IsCalculateThreadAboutToExit = false;
>   SDL_CreateThread(StartCalculateThread);
> }
>
> bool IsThreadStillRunning()
> {
>   return (!IsCalculateThreadAboutToExit);
> }

I realize this is only an example, but with the "IsThreadStillRunning"
procedure, I feel compelled to say that that'd peg the processor at 100%
utilization. Andi t begs the question, if a subordinate thread is spawned
off, only to be waited on by another thread, why was the subordinate
thread created in the first place?

There are very few reasons to create another thread for something, and
more often I see thread abuse than use. It might be tempting (whizzy/cool)
to use a thread, but there are so few circumstances when it's actually
needed that when someone says they need a thread for something, more often
than not they don't!

-->Neil

-------------------------------------------------------------------------------
Neil Bradley            What are burger lovers saying
Synthcom Systems, Inc.  about the new BK Back Porch Griller?
ICQ #29402898	        "It tastes like it came off the back porch." - Me





More information about the SDL mailing list