We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Threading! (Read 1069 times)
Threading!
Mar 14th, 2008, 11:58pm
 
Hey, I did a quick search, and couldn't find a topic about this...

Anyways, I think that Sketchbook should run the client program in another thread.
Because, what if I do something stupid and the program ends up in an infinite loop? Or if it takes a lot of time to do something?
I end up with terminating the process, which also terminates the editor - this means, that I lose changes!
And if I'm not careful, and forget to save (I tend to save very often, saying for other people now), I could lost hours of work!
Re: Threading!
Reply #1 - Mar 15th, 2008, 3:08am
 
it does run in another thread. otherwise the entire editor window, menus, etc would be completely unavailable while a sketch is running.

that said, there are ways that sketches can lock up the machine, e.g. a tight while() loop that never completes. as it happens, rev 0136 will be closer to what you're looking for.
Re: Threading!
Reply #2 - Mar 15th, 2008, 9:50am
 
Well, that's what I meant - to put the COMPLETE program in another thread - right now, it doesn't look that way.

And if you think about it, it might have been done this way, without threads (pseudo-code):
--------------------
gui_update();
program_setup();
while(window_open(processing))
{
 gui_update();
 if(window_open(program))
 {
   program_callbacks();
   program_draw();
 }
}
--------------------

Basically, it runs the drawing in the same thread, the only difference is that it also does GUI update in the loop...
That would explain the fact that while(true) loops in the program (program = sketch) stop the whole IDE from working... Processing stops at while(true) inside program_draw()

Well, another explanation would be this (same effect):
--------------------
Thread main;
Thread prog;

main.gui_update();
prog.program_setup();
prog.wait(); // waits for the thread to return
while(window_open(processing))
{
 main.gui_update();
 if(window_open(program))
 {
   prog.program_callbacks();
   prog.wait();
   prog.program_draw();
   prog.wait();
 }
}
--------------------
PS: Yes, I know that this isn't how the actual program works (I really don't feel like looking into its code either), hence the term pseudo-code.
Page Index Toggle Pages: 1