Shop OBEX P1 Docs P2 Docs Learn Events
Varable name with cogid — Parallax Forums

Varable name with cogid

user82user82 Posts: 9
edited 2010-12-08 11:20 in Propeller 1
hi!

i want to start a task on several cogs in parallel and make them use var1,var2 etc

now "cogid" is not recognized if i write "varcogid"

how can i solve this?(hope its not needed on compile time because i wanted to write one PUB for all cogs)

greetings
user

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2010-12-08 05:03
    What about something like this
    CON
      ccnt = 4
      
    VAR
      long  storage[8]
      long  stack[16*ccnt]
    
    PUB null | idx
    
      idx := 0
      repeat ccnt
        cognew(method, @stack[16*idx++])
    
    PRI method | private
    
      private := storage[cogid]
    
    It starts 4 cogs each of which uses a private slot in the storage array.
  • user82user82 Posts: 9
    edited 2010-12-08 08:41
    kuroneko wrote: »
    What about something like this
    CON
      ccnt = 4
      
    VAR
      long  storage[8]
      long  stack[16*ccnt]
    
    PUB null | idx
    
      idx := 0
      repeat ccnt
        cognew(method, @stack[16*idx++])
    
    PRI method | private
    
      private := storage[cogid]
    
    It starts 4 cogs each of which uses a private slot in the storage array.


    hmh yes thats good my concept is:

    one "master" cog
    several worker cods that do exactly the same thing

    now every worker cog gets its global variable with number 1-7 where it puts the results that cog0 needs for doing its own work based on the results the other cogs deliver

    i could use the bunch of longs for doing this, thank you!
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-12-08 09:19
    Don't forget: you can also start Spin cogs with parameters. So something like this will also work:
      cognew(method(@var1), @stack1)
      cognew(method(@var2), @stack2)
      codnew(method(@var3), @stack3)
      ...
    
    PUB method(var_addr)
    
      ...
    

    -Phil
  • user82user82 Posts: 9
    edited 2010-12-08 11:20
    Don't forget: you can also start Spin cogs with parameters. So something like this will also work:
      cognew(method(@var1), @stack1)
      cognew(method(@var2), @stack2)
      codnew(method(@var3), @stack3)
      ...
    
    PUB method(var_addr)
    
      ...
    

    -Phil

    also good hint, thanks

    i will test both methods since its a first test code
Sign In or Register to comment.