Shop OBEX P1 Docs P2 Docs Learn Events
Concurrent objects? — Parallax Forums

Concurrent objects?

HughHugh Posts: 362
edited 2009-11-18 22:37 in Propeller 1
Hi guys.

I had assumed that if I declare two instantiations of an class using unique names I could have two similar processes running concurrently (in separate cogs). I.e.,

OBJ 
  uart1          :               "FullDuplexSerial"
  uart2          :               "FullDuplexSerial"



However, this appears not to be the case - trying to use both causes each to stop. Was I being too naive or do I need to avoid some elephant trap of which I am not yet aware?

Thanks for looking!

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hugh - the thinking woman's Geoffrey Pyke.

Comments

  • KyeKye Posts: 2,200
    edited 2009-10-13 11:51
    Um, yes you can use the same object twice. You also need to start the object twice and use each different one with its different name. Also, make sure they are not on the same pins.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-10-13 15:56
    The answer is not quite that simple. Some objects are not designed to be used concurrently. If all of an object's hub variables are in a VAR section, multiple instances of that object can typically run without mutual interference. However, if any of its hub variables are defined in a DAT section, then those variables will be shared by all of the object's instances, most likely leading to trouble. Specifically, some objects may use a DAT variable to store the number of a cog it started, so it can stop the cog via a stop method, when it's called, or upon the next time start is called.

    Short answer: it depends, and you have to examine the object itself to make sure. iMO, it should be a requirement for any object submitted to the OBEX to include a statement as to whether it is "multiple instance safe".

    -Phil
  • Bill HenningBill Henning Posts: 6,445
    edited 2009-10-13 16:08
    Better yet, use the quad serial object - it only uses one cog for up to four serial ports!
    Hugh said...
    Hi guys.

    I had assumed that if I declare two instantiations of an class using unique names I could have two similar processes running concurrently (in separate cogs). I.e.,

    OBJ 
      uart1          :               "FullDuplexSerial"
      uart2          :               "FullDuplexSerial"
    



    However, this appears not to be the case - trying to use both causes each to stop. Was I being too naive or do I need to avoid some elephant trap of which I am not yet aware?

    Thanks for looking!
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Please use mikronauts _at_ gmail _dot_ com to contact me off-forum, my PM is almost totally full
    Morpheus & Mem+dual Prop SBC w/ 512KB kit $119.95, 2MB memory IO board kit $89.95, both kits $189.95
    www.mikronauts.com - my site 6.250MHz custom Crystals for running Propellers at 100MHz
    Las - Large model assembler for the Propeller Largos - a feature full nano operating system for the Propeller
  • HughHugh Posts: 362
    edited 2009-10-13 19:46
    Aha! Thanks. It makes sense now.

    Thanks for the tip, Bill. cool.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hugh - the thinking woman's Geoffrey Pyke.
  • RumpleRumple Posts: 38
    edited 2009-11-18 21:10
    Phil Pilgrim (PhiPi) said...
    The answer is not quite that simple. Some objects are not designed to be used concurrently. If all of an object's hub variables are in a VAR section, multiple instances of that object can typically run without mutual interference. However, if any of its hub variables are defined in a DAT section, then those variables will be shared by all of the object's instances, most likely leading to trouble. Specifically, some objects may use a DAT variable to store the number of a cog it started, so it can stop the cog via a stop method, when it's called, or upon the next time start is called.
    I looked at the DAT section of·FullDuplexSerial and saw nothing that looked like a variable declaration (mind you, I'm not (yet) an assembly guy).··So this means that I can get away with running eight instances of·FDS in eight different cogs simultaneously?· I suspect I'll soon be wanting to do something like that...

    Tim
  • BergamotBergamot Posts: 185
    edited 2009-11-18 21:45
    Rumple said...
    Phil Pilgrim (PhiPi) said...

    The answer is not quite that simple. Some objects are not designed to be used concurrently. If all of an object's hub variables are in a VAR section, multiple instances of that object can typically run without mutual interference. However, if any of its hub variables are defined in a DAT section, then those variables will be shared by all of the object's instances, most likely leading to trouble. Specifically, some objects may use a DAT variable to store the number of a cog it started, so it can stop the cog via a stop method, when it's called, or upon the next time start is called.

    I looked at the DAT section of FullDuplexSerial and saw nothing that looked like a variable declaration (mind you, I'm not (yet) an assembly guy). So this means that I can get away with running eight instances of FDS in eight different cogs simultaneously? I suspect I'll soon be wanting to do something like that...


    Tim
    You might want to reserve a cog for actually doing stuff with the data
  • localrogerlocalroger Posts: 3,452
    edited 2009-11-18 22:37
    fullduplexserial is multiple instance safe -- I've used it that way. Furthermore it's about half the size of the quad serial object, so if Hub RAM is tight but you have a cog to spare, it can be a better solution.
Sign In or Register to comment.