Sharing / passing results between cogs.
Hugh
Posts: 362
Folks,
Apologies if I am being thick / naive here, but...
I have one cog whirring away on one method, at the end of which it updates some information being displayed to VGA. I want to start another method on a different (new) cog, but make the results of that method available to the data of the other cog so that they are included in the displayed results. How is best to do this - if it is possible at all?
Thanks
Hugh
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hugh - the thinking woman's Geoffrey Pyke.
Apologies if I am being thick / naive here, but...
I have one cog whirring away on one method, at the end of which it updates some information being displayed to VGA. I want to start another method on a different (new) cog, but make the results of that method available to the data of the other cog so that they are included in the displayed results. How is best to do this - if it is possible at all?
Thanks
Hugh
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hugh - the thinking woman's Geoffrey Pyke.
Comments
It's possible to do what you describe, but whether that will do what you want is another question entirely.
Thanks!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hugh - the thinking woman's Geoffrey Pyke.
About your question ...
If all your routines are written in Spin in one file (object), they already share the variables in the VAR section(s). If you have two methods, each running in its own cog, they can already communicate by using the same variables in both methods. You shouldn't get into trouble if only one method (in one cog) changes a particular variable and one or more methods (in other cogs) use the value of that variable. This is what you're doing with the display routine. It only reads the variable value while some other cog writes it.
Do take a look at the LOCKxx statements. These are used to allow only one cog at a time to access a variable or group of variables and are needed for anything more complicated than the read/write example I gave above.