Next available cog
Dave Matthews
Posts: 93
in Propeller 1
The reference for the COGNEW command reads: 'Start the next available cog to run Spin code or Propeller Assembly code.'
What is the next available cog? If an object had launched code into what turns out to be Cog3, is the next available then Cog 4? If the object uses the Stop/Start public interface methods, if the object stops Cog 3 before the subsequent Cognew command, is the next available cog then Cog 3 again? If Cog 7 is in use, does the command start checking for a free cog starting at Cog 0 and counting up?
Dave
What is the next available cog? If an object had launched code into what turns out to be Cog3, is the next available then Cog 4? If the object uses the Stop/Start public interface methods, if the object stops Cog 3 before the subsequent Cognew command, is the next available cog then Cog 3 again? If Cog 7 is in use, does the command start checking for a free cog starting at Cog 0 and counting up?
Dave
Comments
-Phil
In general it does not help. A program can be starting and stopping COGs at unpredictable times, depending on timing and object load/start order etc. Potentially the starting and stopping of COGs can happen in response to external events in which case it is effectively random. That "next COG available" is not knowable.
A cog that tries to find out which is the next free COG can always be wrong. Having determined, somehow that COG N is free, some other running COG may start to use COG N before our first COG has a chance to do anything with what it discovered.
Bottom line is that unless you have total control over when everything happens in your code the problem is, in general, impossible.
And as Phil says, you don't need to know. A program should not care which COG is used to do what any more than it cares which memory locations are used to store its code and variables.
Dave