Dennis Ferron
04-04-2009, 03:30 AM
I'm trying to debug a Spin object where my start routine launches a worker subroutine second Spin cog. I'm trying to use some vars to communicate between the parent object and the subroutine started by the parent, but it seems like when I try to access those vars in the subroutine, all I get are copies of the variables. For instance:
VAR
long TestComm
long Stack[16]
PUB Start
TestComm := 11
cognew(DoWork, @Stack)
repeat
TestComm := 22
PRI DoWork
repeat
' Print out TestComm: value is 11, never prints 22
So, I'm guessing cognew on a Spin routine creates a copy of the object? What if you had a lot of data used by the worker routine, that isn't needed by the Start'ing object; is there are way to avoid making 2 copies?
If it is another copy, I wonder if there is a hack to set the value of the object base address pointer within the DoWork routine so that it points again at the original object, so that referring to the variables refers to the original ones and not the copy? It would be something like cognew(DoWork(@@0), @Stack) and DoWork(base_address) would reset its own base address to the value passed in?
VAR
long TestComm
long Stack[16]
PUB Start
TestComm := 11
cognew(DoWork, @Stack)
repeat
TestComm := 22
PRI DoWork
repeat
' Print out TestComm: value is 11, never prints 22
So, I'm guessing cognew on a Spin routine creates a copy of the object? What if you had a lot of data used by the worker routine, that isn't needed by the Start'ing object; is there are way to avoid making 2 copies?
If it is another copy, I wonder if there is a hack to set the value of the object base address pointer within the DoWork routine so that it points again at the original object, so that referring to the variables refers to the original ones and not the copy? It would be something like cognew(DoWork(@@0), @Stack) and DoWork(base_address) would reset its own base address to the value passed in?