Shop OBEX P1 Docs P2 Docs Learn Events
Sharing / passing results between cogs. — Parallax Forums

Sharing / passing results between cogs.

HughHugh Posts: 362
edited 2008-12-07 16:30 in Propeller 1
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.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-07 15:42
    I don't understand why you need two cogs for the computation. If one cog's calculation makes use of another cog's calculation, the first cog has to effectively wait for the 2nd cog to finish so it has valid data before it does its own calculation. In that case, you might as well just use one cog for the calculations since they're really done serially. If there's some overlap possible (like the 2nd cog's values are only needed late in the 1st cog's calculations), please explain in more detail.

    It's possible to do what you describe, but whether that will do what you want is another question entirely.
  • HughHugh Posts: 362
    edited 2008-12-07 16:03
    I was trying to be clever. It will be many moons before I am a smart as you, Mike!

    Thanks!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hugh - the thinking woman's Geoffrey Pyke.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-07 16:30
    Remember that smart is different from knowledgeable. You may well be smarter than me. I have a lot of experience from years of fiddling with electronics in general, then computers. I pay attention to things I've read and seem to be pretty good at remembering a lot of it. I make use of the internet to find explanations for things I don't remember or don't know enough about.

    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.
Sign In or Register to comment.