Do you dynamically start and stop cogs?
Cluso99
Posts: 18,069
in Propeller 2
Do you dynamically start and stop cogs? If so, would you be so kind to give some details please.
I dynamically start and stop cogs in my PropOS. For example each OS command (such as DIR, COPY, etc) all load/start a new cog which starts _cmd.cmd and stops itself.
The spin/pasm compiler (Originally Sphinx by Michael Park) also starts and stops cogs. If you run a program either under the OS it gets started and may in turn start other cogs. If you "run" a binary, it loads/runs the binary after stopping all cogs, and that binary may start other cogs.
I don't recall any other programs of mine that dynamically start and stop cogs.
I dynamically start and stop cogs in my PropOS. For example each OS command (such as DIR, COPY, etc) all load/start a new cog which starts _cmd.cmd and stops itself.
The spin/pasm compiler (Originally Sphinx by Michael Park) also starts and stops cogs. If you run a program either under the OS it gets started and may in turn start other cogs. If you "run" a binary, it loads/runs the binary after stopping all cogs, and that binary may start other cogs.
I don't recall any other programs of mine that dynamically start and stop cogs.
Comments
My FFT can can use 1, 2, 4 cogs to spread the load for a bit of a performance boost. It's written in C and uses OpenMP to to the parallelization. I'm not totally sure but as a far as I know does not pre-allocate the max required COGs to do this. I see no reason why it should. Code is here: https://github.com/ZiCog/fftbench
I posted a Spin version of the JKISS32 pseudo random number generator. Which produces much better and vastly longer period sequences of random numbers than most languages implement. When you want something more random but don't want to waste a COG on Chips Real Random object it has a seed function that fires up a COG to get a random number from Real Random to use as a seed. That COG is then released.
Jonny Mac used that code for some stage effects so Limp Bizkit may well have used dynamic COGs on stage!
i have no intention in wanting it removed - it's a fantastic feature, perhaps way under used.
heater,
I am particularly interested where multiple cogs are started and stopped. Programs that start objects that then start more cogs are not what I am after as they don't stop cogs for restarting.
Yes, possibly Jon might start and stop cogs, perhaps running on time sequences.
It used cognew everywhere. I just checked, and the only coginit in the whole thing is inside Kye's SD card driver in the program loader.
The FFT will only fire up 3 new COGs to split the processing over 4 COGs when you call on it to do an FFT. When it's done those 3 COGs are stopped.
Similarly the JKISS32 only fires up a Real Random COG when you call the "init" or "seed" function (I forget what I called it now), which you can do at any time.
Which is interesting now that I think about it. If you were using both of those in a program you would have to be sure there there is enough free COGs to run them both at the same time. Or you would have to be sure you never run them at the same time if you are short of COGs to do so.
Yes, nicely put.
There is no 'completely free' COG allocate, you do have to make sure you never try to ask for 9 in P1, or 17 in P2.
The pseudo random number generator is actually only a method that when called runs in the calling COG. But it has this random seeding method that fires up a COG briefly to get a real random number.
I have never stopped a cog... but that is only because all of my work has been experimental for prototyping.
I can't imagine writing a systems-type application for actual use that didn't dynamically allocate resources.
As the system gets smarter, resource allocation is going to be increasingly more important.
The robots we build next will have more sensors than are needed at any one moment.
It would be a waste of batteries not to shut them down until needed.
Which functions run depends on what a sensor may detect/measure and what action needs to be taken. My functions and library functions may start and stop cogs multiple times depending on the situation, and I can't predict which ones will be open at the same time, or what cog they will start. I try to program so that worst case, no more than 8 cogs try to be running at the same time.
Tom
We keep getting reminded that the P1 & P2 are not for running an OS
...which means a Prop OS will look a bit different from the usual stuff out there.