Spin Start/Stop Methods
I've got an question:
The Propeller Manual (p119 3rd paragraph) says that if an object has methods to Start and Stop cogs, you should call the Stop method before the Start method, otherwise "a new cog would start up and overwrite another cog's workspace variables, such as Stack."·I don't understand the meaning of this statement. cognew() does not start a cog if none are available, and why would you care if you·erase something you're going to overwrite anyway? Is this a general statement, or is it specific to the example in the book (Output.spin)?
Thanks,
Stephen
The Propeller Manual (p119 3rd paragraph) says that if an object has methods to Start and Stop cogs, you should call the Stop method before the Start method, otherwise "a new cog would start up and overwrite another cog's workspace variables, such as Stack."·I don't understand the meaning of this statement. cognew() does not start a cog if none are available, and why would you care if you·erase something you're going to overwrite anyway? Is this a general statement, or is it specific to the example in the book (Output.spin)?
Thanks,
Stephen
Comments
Anyway, the conventional way to take care of this is to use the existing "stop" method to stop any currently running cog (for this object) before starting up a new one. Since COGNEW returns the number of the cog used, the "start" method saves this in the workspace and the "stop" method uses this saved value to determine whether there's already a cog running and uses this to stop it. Often the "start" method already has a call to the "stop" method built into it.
So calling stop just makes sure that you don't get undefined results. You could argue that calling the start method more than once is broken behaviour anyway ...
HTH
-Phil