A schedule question
by Bullitt Sesariza · in Torque Game Engine · 11/09/2007 (1:52 am) · 4 replies
Hi, I want to ask about the schedule function. Is it called in a thread or not? If it is, is it locked or not? If I was to change a crucial variable that was being read in the schedule from the outside, what would happen? Thanks in advance.
#2
it runs a big loop which goes something like this:
* service the network
* deal with user input events
* process pending events (including schedules)
* render the scene
* repeat
(i'm not sure those are the components or the right order, but that's the idea)
so what do you mean "from the outside" ?
you mean in some script function besides the one which is scheduled ?
that would be fine.
11/21/2007 (9:37 am)
TGE is essentially single-threaded.it runs a big loop which goes something like this:
* service the network
* deal with user input events
* process pending events (including schedules)
* render the scene
* repeat
(i'm not sure those are the components or the right order, but that's the idea)
so what do you mean "from the outside" ?
you mean in some script function besides the one which is scheduled ?
that would be fine.
#3
sgNewEvent(0, 0, sgSceneLightingProcessEvent::sgTGEPassSetupEventType);
and it does seem like if you enable the multithreaded flag they spawn as extra threads. The mutex/semaphore blocks even make it look thread safe, but I'm not sure how it all works yet.
Scheduled events as called from the Schedule(1000,0,'My function') don't appear to be threads however.
On a related note, if you had a really massive calculation that you wanted to slowly work on in the background (ideally in a separate thread), how might someone go about adding that? Does anyone know of examples where it has been done? I understand multithreaded programming in VB.net, but never figured it out for the C world.
11/21/2007 (11:03 pm)
I'd been looking through the event scheduling as called like this:sgNewEvent(0, 0, sgSceneLightingProcessEvent::sgTGEPassSetupEventType);
and it does seem like if you enable the multithreaded flag they spawn as extra threads. The mutex/semaphore blocks even make it look thread safe, but I'm not sure how it all works yet.
Scheduled events as called from the Schedule(1000,0,'My function') don't appear to be threads however.
On a related note, if you had a really massive calculation that you wanted to slowly work on in the background (ideally in a separate thread), how might someone go about adding that? Does anyone know of examples where it has been done? I understand multithreaded programming in VB.net, but never figured it out for the C world.
#4
IC, thanks for the info. Well, with my past project using SDL, I've used a different thread for a method similar to Torque's scheduling. And I've got to lock the thread so that the variables for the threaded method can not be changed from the main thread. My assumption was Torque's scheduling is multi-threaded. So I was afraid if I have this schedule:
and it was threaded, then if I changed the $myVar's value form the main thread it would go wrong. Well, now it's clear. Thanks guys.
11/22/2007 (1:26 am)
@allIC, thanks for the info. Well, with my past project using SDL, I've used a different thread for a method similar to Torque's scheduling. And I've got to lock the thread so that the variables for the threaded method can not be changed from the main thread. My assumption was Torque's scheduling is multi-threaded. So I was afraid if I have this schedule:
function mySched()
{
if ($myVar == 2)
{
.......
}
}and it was threaded, then if I changed the $myVar's value form the main thread it would go wrong. Well, now it's clear. Thanks guys.
Associate Ross Pawley