|
|
wait_for
#259015
04/03/09 13:39
04/03/09 13:39
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
OP
Expert
|
OP
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
I need a function a to wait until another function b (that a has called) has finished running. I believe I cannot use wait_for though, because many instances of b may be running at the same time. Is there a nice way to do this? here's what wait_for does:
myfunction(myparameter); // call a function with many wait()s (one instance only)
wait_for(myfunction); // wait until myfunction is finished (lite-C only)
Last edited by Germanunkol; 04/03/09 13:44.
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: wait_for
[Re: Germanunkol]
#259025
04/03/09 14:11
04/03/09 14:11
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Sounds right to me.
Can you post the existing function A and function B ? (even an approximation) If I can see what they so I may be able to figure a work-around.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: wait_for
[Re: VeT]
#259078
04/03/09 18:17
04/03/09 18:17
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
OP
Expert
|
OP
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
VeT, i've used similar code before. The Problem is that I want to call the function mutliple times at once, so as soon as one instance is done running, all calling functions would continue. EvilSob, I've not coded the function yet, but here was a test i did to this subject. This is actually using Vet's code as well, but doesn't work at all. (it should take 500 frames before it beeps, right? well, it doesn't. you can try it out...)
#include <acknex.h>
#include <default.c>
FONT* fallbackFont = "Arial#12b"; // truetype font
int lol= 0;
int lol2= 0;
PANEL* testPAN =
{
pos_y = 150;
digits = 0,0,10.4,fallbackFont,1,lol;
digits = 0,12,4,fallbackFont,1,lol2;
flags = SHOW;
}
int theNUMBER()
{
int thenumber = 0;
while(thenumber < 5000)
{
thenumber += 1;
wait(1);
}
return(thenumber);
}
void main()
{
fps_max = 10;
wait(10);
lol = theNUMBER();
while(lol == 0){wait(1);}
beep();
lol2 = 10;
}
Last edited by Germanunkol; 04/03/09 18:18.
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: wait_for
[Re: Germanunkol]
#259095
04/03/09 20:49
04/03/09 20:49
|
Joined: Jul 2008
Posts: 170 Germany, near Mainz
Nicotin
Member
|
Member
Joined: Jul 2008
Posts: 170
Germany, near Mainz
|
I didn't tested it. But you could use an array and proc status... like
var running[100];
function multiple_function(index)
{
beep();
running[index] = 1;
}
function main()
{
var function_number;
multiple_function(function_number);
while(running[function_number] == 0) {wait(1);}
sys_exit();
}
I hope it is at least abit you were asking for? xD
|
|
|
Re: wait_for
[Re: Nicotin]
#259109
04/03/09 22:10
04/03/09 22:10
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Ive just put this together, and basic testing gives it the OK. It may do the job for you if FunctionA noticing the functionB end-time is not too critical. AND you can see the door is open to returning MULTIPLE values/types per instance. I think there is enough documentation to see how to use it. Otherwise just ask... var ID_Done=0, ID_Value=0;
void FunctionB(var ID, var any_other_parameters)
{
//normal function coding
var Value_to_return = random(1000);
/////////////////////////////////////////////////////////////////////////
////completed, set completion flag.
while(ID_Done) wait(1); //wait till ID_Done is unused
ID_Done = ID; //set ID_Done to ID of this instance
ID_Value = Value_to_return; //set return value
/////////////////////////////////////////////////////////////////////////
////untested optional "timeout" safety mechanism in case FunctionA stopped
var t; for(t=0; t<100; t++) { wait(1); if(ID_Done!=ID) break; }
if(ID_Done==ID) ID_Done = 0; //FunctionA not responding
/////////////////////////////////////////////////////////////////////////
}
function FunctionA()
{
//normal function coding
var ReturnFromB = 0;
/////////////////////////////////////////////////////////////////////////
//call FunctionB and wait for it to complete
var ID = random(100000); //generate unique instance number
FunctionB(ID, any_other_parameters); //call FunctionB
while(ID_Done!=ID) wait(1); //Wait for instance to flag completion
ReturnFromB = ID_Value; //get its return value
ID_Done = 0; //release ID_Done for other instances to use
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//Untested Alternate version with "timeout" safety mechanism
//call FunctionB and wait a set period of time for it to complete
var ID = random(100000); //generate unique instance number
FunctionB(ID, any_other_parameters); //call FunctionB
var t; for(t=0; t<100; t++) { wait(1); if(ID_Done==ID) break; }
if(ID_Done==ID) { ReturnFromB = ID_Value; ID_Done = 0; }
/////////////////////////////////////////////////////////////////////////
}
Last edited by EvilSOB; 04/04/09 13:48. Reason: added Timeout safetys
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: wait_for
[Re: EvilSOB]
#259324
04/05/09 13:58
04/05/09 13:58
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
OP
Expert
|
OP
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
Okay... both methods from the two of you pass along an ID to the called function. I think I'll try it with that method. thanks a lot  Micha
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
|