Shop OBEX P1 Docs P2 Docs Learn Events
Is this buffer shared ? — Parallax Forums

Is this buffer shared ?

peterzpeterz Posts: 59
edited 2007-02-05 18:04 in Propeller 1
I have three objects: A,B,C

Object A is the main object, which contains the starting Spin code. Lets say it is running in COG0.
When it starts·it calls object C, which in place launches a new ASM routine in COG1.
Then object A initializes object B which in place launches a new SPIN routine in·COG2.
Threafter·COG0 and COG2 keep calling routines in object C·which communicates with ASM code running in COG1 by means of a buffer.
In object C·this buffer is declared as LONG Buffer[noparse][[/noparse]32] in the SPIN section. The buffer is passed to ASM code by means of 'par'.

Would this buffer be shared among COG0 and COG2· ?

·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-05 15:08
    As is true of Spin code in general, a variable declared in one object (C in this case) is not accessible to another object (A or B) regardless of which Cog is executing the code. You can always declare a method (function) in the object (C) to return the address of the variable or otherwise manipulate it. When variables are shared among several Cogs, you have to take precautions to make sure only one object can change the variables at a time or unpredictable and probably incorrect behavior can result.
  • peterzpeterz Posts: 59
    edited 2007-02-05 15:16
    Sorry, I have not been too explicit I believe.
    From A spin code I call a C Spin routine that manages the Buffer. And the same from B.
    I don't manipulate directly the buffer from A or B, just call a function within C that manages the buffer.
    My question is: say A calls C, and it result in Buffer[noparse][[/noparse]0] to become certain value. If then I call C from B, would Buffer[noparse][[/noparse]0] be the same value ?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-05 15:43
    If the buffer is declared as a VAR (rather than in a DAT section) in C, you will have two separate copies, one declared by A and the other declared by B (as OBJ C: "..."). There is a separate VAR area copy for each OBJ declaration (but only one copy of the DAT area and the code (PUB and PRI)). This isn't always what you want, but that's the way the compiler behaves.
  • peterzpeterz Posts: 59
    edited 2007-02-05 18:04
    So can I do it shared just by changing the folowing in the C OBJ ?

    VAR
    LONG Buffer[noparse][[/noparse]32]

    to....

    DAT
    Buffer LONG 0,0,0,0,0..................0
Sign In or Register to comment.