Event Loop problem
When my object's Run() returns, the thread exits, but the main app still runs. How do I tell the main thread which is in its Run() to quit? I tried QuitApplicationEventLoop(); from the thread but it doesn't do anything. I just need a way to have the main app exit when my thread exists. Can someone explain to me how to do this?
There is another option, run my own event loop instead of using the default one. I have had limited success with this, because at sometime the event loop starts to spin. I copied some example code to use as my event loop, but as I said, it goes nuts sometimes. The "count" was added by me, but the rest is directly copied from some apple document somewhere.
void EventPump()
{
EventRecord theEvent;
int Count = 0;
// Cycle through all events
while (1 == GetNextEvent(everyEvent, &theEvent))
{
Count++;
// Sometimes we get in an infinit message loop. This will limit message proccessing
// to 100 messages max per call.
if ( 100 == Count )
{
break;
}
AEProcessAppleEvent(&theEvent);
}
}
Most of the time, for hours, sometimes for days, that works fine, but then Ill suddenly see my process at 99% cpu usage and stuck in this loop, and will eventually crash. The crash log is how I know where the problem is. Maybe there is a simple fix or someone can give me another simple event loop that will not lock up.
I need that or a way from my threaded app to cause the main event loop to exit when the thread exits. Any help is greatly appreciated.
EMac, Mac Mini, Mac OS X (10.4.6)