Sharing a value between different cogs
jbalat
Posts: 96
What is the go with sharing a global variable ?
If I read a frequency and then store it into a long variable on one cog, can I access it at any time from another cog or the main method or do I need to lock and unlock functions ?
My understanding is that Writing of a long variable may take more than one hub turn.. so if you try to read it from another cog it may be corrupted if the whole value is not written to memory
Please explain...
If I read a frequency and then store it into a long variable on one cog, can I access it at any time from another cog or the main method or do I need to lock and unlock functions ?
My understanding is that Writing of a long variable may take more than one hub turn.. so if you try to read it from another cog it may be corrupted if the whole value is not written to memory
Please explain...
Comments
A single long in the hub will be updated in one hub turn. You only need to use the locks if you are updating a multi-long structure then you need to use the locks.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1st rule of finance...Don't lose money.
Never be ashamed of making an honest·profit.
Live within your means...Make do, or do without.
·
As one full HUB turn is 16 instruction cycles, 8 longs can be written to HUB-RAM in one turn if all COGs want to write something.
Any cog can then reference or modify it safely without using the "@" modifier
If you talk PASM, things get more complex. But that's a lesson to learn in future ;o)
I didn't mean to confuse the issue.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1st rule of finance...Don't lose money.
Never be ashamed of making an honest·profit.
Live within your means...Make do, or do without.
·