How to run multiple cogs and have multiple error checking strings?
I'm doing my first experiment where I'm combining different pieces of code and trying to dedicate cogs to the different methods.
When I use a CogNew command, and call a method with some stack space, is that sufficient to start experiments with running multiple cogs, or should I be aware of something else? Can I use the basic format below for my methods? (the example code was done without an IDE from memory, so forgive some of the minor syntax error)
Post Edited (turbosupra) : 7/16/2010 6:23:11 PM GMT
When I use a CogNew command, and call a method with some stack space, is that sufficient to start experiments with running multiple cogs, or should I be aware of something else? Can I use the basic format below for my methods? (the example code was done without an IDE from memory, so forgive some of the minor syntax error)
PUB Main
Cognew(Method1, @method1stack)
Cognew(Method2, @method2stack)
Cognew(Method3, @method3stack)
Cognew(Method4, @method4stack)
repeat
if something
option1 := option2
else
option1 := option3
PUB Method1
if ina[noparse][[/noparse]8] == 1
test1 := test2
debug.str(string("test 1 equals test 2",13))
else
test1 := 4
debug.str(string("test 1 equals 4",13))
PUB Method2
if ina[noparse][[/noparse]8] == 1
test1 := test2
debug.str(string("test 1 equals test 2",13))
else
test1 := 4
debug.str(string("test 1 equals 4",13))
PUB Method3
if ina[noparse][[/noparse]8] == 1
test1 := test2
debug.str(string("test 1 equals test 2",13))
else
test1 := 4
debug.str(string("test 1 equals 4",13))
PUB Method4
if ina[noparse][[/noparse]8] == 1
test1 := test2
debug.str(string("test 1 equals test 2",13))
else
test1 := 4
debug.str(string("test 1 equals 4",13))
Post Edited (turbosupra) : 7/16/2010 6:23:11 PM GMT

Comments
At best you will get an output all scrambled like "ttteeesssttt 123 eeeqqq...."
To fix that put the debug.str(....) into a method with a lock around the debug.str call.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
Thanks for the response, do you mean to put the debug.str in its own method? Also how do I put a lock around the debug.str call?
Yes put the debug.str(...)) into a common method used by all your concurrent methods.
Something like:
PUB printstr(astring) ' Do the lock thing here debug.str(astring) ' Do the lock release thing hereI guess you will have to do the locknew some where at the beginning of your program prior to starting the cogs.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
Still, using @heater's suggested method may be easier. Nice to explore all opportunities.
Cheers,
--Steve
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Pages: Propeller JVM
Mike, if I understand what you are saying correctly, you are saying that once the cog is started in PUB Main, before the repeat loop, the cog continues to run until it is told to stop, or forced to stop through a chip reset? That is what I want, and I'd just like to make sure I understand the operation of multiple cogs correctly. I need a couple of dedicated cogs at the moment.
If you want them to continue again from the "if" you will have to put a "repeat" at the beginning of each method and indent the "if" - "else" parts.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
So if I call a newcog and have a repeat loop inside of the method, they cogs will run as dedicated cogs repeating the code in that loop?
Then if I wanted to share a cog that didn't use very many system cycles I could just put more code into the method that cog is calling?
Yep, you got it.
You can then put more code into any one or all of those methods that you have started in cogs. You can call other new methods from those cogs as well.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
How much of the system resources does this use? It has ~10 methods.
I can see by the comments in the top of it that it is pretty powerful, might take me a few months to figure out how to use it though [noparse]:)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Pages: Propeller JVM