Anybody know what would happen if an R-30iA had two concurrently running programs and both programs called the same subprogram at the same time? I've written a subprogram to automate a common operation in my two concurrent programs, but I don't want them to crash the machine if they both try to use the subprogram at the same time. Thanks!
Multiple calls for same subprogram?
-
SirCumference -
August 28, 2014 at 4:35 PM -
Thread is marked as Resolved.
-
-
You will get an error stating "program already running", and it will fault.
You can use I/O to check if the called program is running already in either program and jump over the call. -
If the tasks do not have the same group assigned to them, and they both call the same subprogram (which would have to have no group), each task will run separate invocations of the subprogram in their own stack frames. What I am saying is that each task will create its own "copy" of your subprogram and execute it independently of the other task. This could cause problems if the sub program controls IO, as you would have two copies fighting each other.
You could use a register or a flag to lock the program from the other task when it is being used by a task.
For example:
Code
Display More/PROG MACHINE_CRASHER DEFAULT_GROUP = *,*,*,*,*; /MN 1: WAIT F[1:Prog Unlocked]=(ON) ; 2: !Lock the program, since it is free ; 3: F[1:Program Unlocked]=(OFF) ; 4: Machine logic here. 5: !All done. Unlock program. ; 6: F[1:Prog Unlocked]=(ON) ; /POS /END
With the above logic, if both tasks called the same subprogram, the task that called it first will lock the program, causing the second task to wait on the flag bit until the first task is finished.
-
hmm i have been putting quite a bit of thought into this problem. i still haven't really solved it yet. using flags as a semaphore works as long as the task always completes. but if it gets aborted or hung up on a wait or something the flag will never drop. i have not been able to find a set of system variables that gives me all the info i want about tasks, so i don't think there is a way to solve this in TPP. I started to write a Karel program that would search through all of the running tasks for a program name, and return some info using the GET_TSK_INFO builtin. i ended up getting distracted, but i still would like a TPP program that could do this, as the folks i work with prefer to do as much as we can without using Karel. any ideas?
$SHELL_WRK.$rout_name program that is currently being edited.
$TP_DEFPROG selected program on TP select Menu.beyond those, all i can find are PNS or RSR task variables.