Shop OBEX P1 Docs P2 Docs Learn Events
Passing values between cogs — Parallax Forums

Passing values between cogs

agodwinagodwin Posts: 72
edited 2008-11-05 19:27 in Propeller 1
In some of the communication between cogs, I've assumed that a LONG will be read or written atomically : that the access is a single operation and will be completed within the hub access slot.

Can this be relied on, or do I have to use the semaphores for any such accesses ? I've assumed that I only need semaphores to protect accesses to multiple objects.

Are there any conditions when it won't be true : misaligned longs for instance ?

-adrian

Comments

  • Harrison.Harrison. Posts: 484
    edited 2008-11-05 19:22
    agodwin said...
    In some of the communication between cogs, I've assumed that a LONG will be read or written atomically : that the access is a single operation and will be completed within the hub access slot.

    Can this be relied on, or do I have to use the semaphores for any such accesses ? I've assumed that I only need semaphores to protect accesses to multiple objects.
    Access to longs, words, and bytes are atomic in SPIN and PASM. I believe this is also stated in the manual somewhere. You'll only need semaphores if you are accessing blocks of memory.
    agodwin said...

    Are there any conditions when it won't be true : misaligned longs for instance ?
    You can't access longs via long[noparse]/noparse or rdlong unless they are long aligned. I believe the architecture ignores the lowest 2 bits in the address for longs, and the lowest bit for words. Variable declarations in the VAR and DAT sections automatically align based on the type you choose.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-05 19:22
    1) Access to longs or words is atomic. It's done with a RDLONG/WRLONG or RDWORD/WRWORD instruction which is a hub instruction and is, by definition, atomic.

    2) You can't access longs (or words) that are not on the appropriate boundary. All long addresses have their lower two bits ignored and all word addresses have their lower bit ignored.

    3) You don't need semaphores for long/word access
  • agodwinagodwin Posts: 72
    edited 2008-11-05 19:27
    Thanks - that seems reasonable but I realised I was in deep trouble if it wasn't ..

    -adrian
Sign In or Register to comment.