Cogs
codeking
Posts: 39
Does a cog stop once the function it's set to run is finished so you can set another function to it with cognew? Or do you have to set another function with coginit?
Post Edited (codeking) : 1/7/2007 5:09:18 PM GMT
Post Edited (codeking) : 1/7/2007 5:09:18 PM GMT
Comments
You could write some code that was just loaded into a cog, ran to the end and then stopped. Once it had completed "its function" it would stop and the cog would be free.
But if you look at most programs an object is loaded into the cog that runs continously in a loop, the object provides functions that allow the user to access the data the cog produces and also send it data. These functions do not require the cog to be restarted every time they are used. The cog keeps on going until it is stopped.
It is better to have this sort of program that runs continously because you do not have the cog load delay before each function call. If however it was a one off process used to set up some hardware then it might make sense.
Why would you want to use coginit on an already initialized cog??? I suspect you need to revist the manual.
Graham
Using coginit on an already created cog would not help. The major delay is in reloading the cog's memory and both coginit and cognew do this as part of the startup process. It is not possible to initialize a cog without reloading its memory (completely!) This was designed in to prevent the Spin interpreter from being copied (among other things).