Shop OBEX P1 Docs P2 Docs Learn Events
Shared Variables — Parallax Forums

Shared Variables

JWoolstonJWoolston Posts: 4
edited 2008-03-18 19:12 in Propeller 1
I have an application where one cog will be writing an array of six values and another reading from it. In this particular case the ability for the write cog to change say, value 6 while the read cog is only on value 4 would be beneficial, allowing for the speediest variable updates possible....is there any reason other than bad programming practice why this could not be done? I seem to remember something about issues if one cog tries to read and index while the other cog tries to write to the same index.

Comments

  • parskoparsko Posts: 501
    edited 2008-03-18 18:54
    The only time you have an issue is when two cogs are trying to write to the same place at the same time (aka Cross-Cog-Clobbering). Or, when you want the new value immediately. Otherwise, you can have one read while another writes without any issues (besides the potential of the value being old when you read it). If you want the latest, use a flag, or semaphore. Normally it isn't an issue though. So, your writing cog will continue to write, while the reading cog will simply read those values, and grab the most recent that has been written (within the 22 clock cycle write period).

    -Parsko
  • JWoolstonJWoolston Posts: 4
    edited 2008-03-18 19:12
    Cool, that simplifies and speeds my code greatly. Thanks.
Sign In or Register to comment.