Torque_multithread Problems
by Gary "ChunkyKs" Briggs · in Torque Game Engine · 04/30/2007 (4:44 pm) · 3 replies
If you disable TORQUE_MULTITHREAD [comment out the line in torqueConfig.h], then after building, torque 1.5.1 [intel macbook pro core2 duo] immediately exits on startup, /a la/
So after poking about, it seems the event itself is being generated in macCarbEvents.cc, here:
I bookended the pthread_kill with #ifdef TORQUE_MULTITHREAD. I don't understand why this signal is necessary in the first place, really, but thar you have it.
I also don't know if bookending just this call actually fixes what's really wrong here. If Paul or some other mac guru could bless this, or explain how to fix it some other way...
Gary (-;
Quote:Torque-MacCarb-Debug has exited due to signal 14 (SIGALRM).
So after poking about, it seems the event itself is being generated in macCarbEvents.cc, here:
static void _OnActivate(bool activating)
{
if(activating)
{
Input::activate();
Game->refreshWindow();
platState.backgrounded = false;
pthread_kill(platState.torqueThreadId, SIGALRM);
}
else
{
Input::deactivate();
platState.backgrounded = true;
}
}I bookended the pthread_kill with #ifdef TORQUE_MULTITHREAD. I don't understand why this signal is necessary in the first place, really, but thar you have it.
I also don't know if bookending just this call actually fixes what's really wrong here. If Paul or some other mac guru could bless this, or explain how to fix it some other way...
Gary (-;
#2
Here's why that signal is there: background sleep time. Lets say you set the background sleep time to something pretty high, like 9000 or so. If you bring another app into the foreground, Torque will throttle itself by sleeping for 9 seconds each frame. The sleep() function does not return until it times out, or until a signal is recieved.
So, when in the background, the Torque thread is sleeping most of the time, and the RAEL thread is spinning. When the RAEL thread sees that we're once again the forground app, it sends the Torque thread an alarm clock signal, and wakes it up.
If it didn't, then when you clicked on a backgrounded Torque window, Torque would remain frozen & paused until the timeout is up. You don't want to wait for several seconds for your game to start being responsive again, so I send the alarm clock signal.
Share and Enjoy.
/Paul
05/18/2007 (8:00 pm)
Hey, good catch with the ifdefs!Here's why that signal is there: background sleep time. Lets say you set the background sleep time to something pretty high, like 9000 or so. If you bring another app into the foreground, Torque will throttle itself by sleeping for 9 seconds each frame. The sleep() function does not return until it times out, or until a signal is recieved.
So, when in the background, the Torque thread is sleeping most of the time, and the RAEL thread is spinning. When the RAEL thread sees that we're once again the forground app, it sends the Torque thread an alarm clock signal, and wakes it up.
If it didn't, then when you clicked on a backgrounded Torque window, Torque would remain frozen & paused until the timeout is up. You don't want to wait for several seconds for your game to start being responsive again, so I send the alarm clock signal.
Share and Enjoy.
/Paul
#3
Thanks,
Gary (-;
05/19/2007 (9:05 pm)
Make sense; so is it the right thing to just remove that if TORQUE_MULTITHREAD isn't set?Thanks,
Gary (-;
Torque Owner Gary "ChunkyKs" Briggs
Index: engine/platformMacCarb/macCarbMain.cc =================================================================== --- engine/platformMacCarb/macCarbMain.cc (revision 23) +++ engine/platformMacCarb/macCarbMain.cc (working copy) @@ -46,7 +46,9 @@ virtual void run(S32 arg) { - signal(SIGALRM, _MacCarbSignalHandler); +#if defined TORQUE_MULTITHREAD + signal(SIGALRM, _MacCarbSignalHandler); +#endif _MacCarbRunTorqueMain(); } }; Index: engine/platformMacCarb/macCarbEvents.cc =================================================================== --- engine/platformMacCarb/macCarbEvents.cc (revision 23) +++ engine/platformMacCarb/macCarbEvents.cc (working copy) @@ -153,7 +153,9 @@ Input::activate(); Game->refreshWindow(); platState.backgrounded = false; +#if defined TORQUE_MULTITHREAD pthread_kill(platState.torqueThreadId, SIGALRM); +#endif } else {Gary (-;
EDIT: Heh. Heh heh. Sometimes I even do stuff the same way twice in a row.