PDA

View Full Version : Is this buffer shared ?



peterz
02-05-2007, 06:08 PM
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[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· ?

·

Mike Green
02-05-2007, 11:08 PM
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.

peterz
02-05-2007, 11:16 PM
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[0] to become certain value. If then I call C from B, would Buffer[0] be the same value ?

Mike Green
02-05-2007, 11:43 PM
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.

peterz
02-06-2007, 02:04 AM
So can I do it shared just by changing the folowing in the C OBJ ?

VAR
LONG Buffer[32]

to....

DAT
Buffer LONG 0,0,0,0,0..................0