Using multiple cogs and stack
rtarbell
Posts: 7
Hello all,
I have read through some of the tutorials and basic programming using Spin and the Propeller, and I wanted to ask about the syntax using multiple cogs:
looking in an example posted in this forum,
VAR
Long Stack0[noparse][[/noparse]20] 'Sets up a stack space for a Cog(processor)
Long Stack1[noparse][[/noparse]20] 'Sets up a stack space for a second Cog(processor)
'long Stack0[noparse][[/noparse]20]: Allocates 20 longs for the stack.
'long Stack1[noparse][[/noparse]20]: Allocates 20 longs for the stack.
The above two lines set up two separate stacks, then:
CogNew(BlinkingLED_A16 (WaitPeriod_Arg), @Stack0)
CogNew(BlinkingLED_A17 (WaitPeriod_Arg), @Stack1)
What does the @Stack0 and @Stack1 commands do? What would happen if I don't include them?
When using separate cogs and making separate stacks for each cog, how can I tell how large I should make the stack for the corresponding cog?
I have read through some of the tutorials and basic programming using Spin and the Propeller, and I wanted to ask about the syntax using multiple cogs:
looking in an example posted in this forum,
VAR
Long Stack0[noparse][[/noparse]20] 'Sets up a stack space for a Cog(processor)
Long Stack1[noparse][[/noparse]20] 'Sets up a stack space for a second Cog(processor)
'long Stack0[noparse][[/noparse]20]: Allocates 20 longs for the stack.
'long Stack1[noparse][[/noparse]20]: Allocates 20 longs for the stack.
The above two lines set up two separate stacks, then:
CogNew(BlinkingLED_A16 (WaitPeriod_Arg), @Stack0)
CogNew(BlinkingLED_A17 (WaitPeriod_Arg), @Stack1)
What does the @Stack0 and @Stack1 commands do? What would happen if I don't include them?
When using separate cogs and making separate stacks for each cog, how can I tell how large I should make the stack for the corresponding cog?
Comments
2) It's best to allow something large (like 20 or 50). There are ways to calculate the amount of stack needed based on the complexity of expressions used in the program, the depth of calls, the number of parameters passed in those calls, etc. It's complicated, not exact, and will vary depending on the control flow in the program (which IF/THEN/ELSE paths get used). There are some sample programs that will fill the stack area with a particular pattern of data and watch it continually to see how much is actually used, then display the result.
I guess it just starts using memory, starting at the end of the program. I just realized that I have a few less longs left than I though in my app!
I think real trouble would occur if you write code that uses recursion. (I think recursion is allowed.).
Yes, you might get into trouble with recursion. Recursion is very useful, but can be difficult to debug if something goes wrong.
FemtoBasic uses recursion for its handling of expressions and there's a check in the expression handling routines for excess recursion.