Shop OBEX P1 Docs P2 Docs Learn Events
atomic 64 bit read/write — Parallax Forums

atomic 64 bit read/write

Is there a way to force a read or write to two consecutive hub RAM longs being executed in two consecutive clock cycles? This would allow atomic access to 64 bit values without having to use locks. A reader would always either see both old values or both new values when another cog writes to them concurrently.

I believe the egg-beater RAM interface could theoretically do this. But a simple wrfast + wflong + wflong sequence doesn't guarantee back-to-back execution. If the first wflong just hits the right slot then the second comes too late and has to wait six (?) cycles for the next 1-out-of-8 slot.

Comments

  • You should be able to do this using SETQ+RDLONG or SETQ+WRLONG .
  • Ah, thanks, that's easy. Sometimes I think too complicated. I thought I have to use the FIFO because the instructions are named read/write-"fast". But the good-old RDLONG/WRLONG are actually faster for this case.
  • cgraceycgracey Posts: 14,155
    edited 2020-01-31 16:25
    The SETQ+RDLONG/WRLONG/WMLONG long reads and writes are actually only one clock cycle apart.

    As long as the writing party does SETQ+WRLONG and the reading parties do SETQ+RDLONG, all using the same Q value and hub address, you effectively get atomic reads and writes of any number of longs (limited by cog RAM size, of course).
  • evanhevanh Posts: 15,916
    If the FIFO is in use I think it'll mess that up because it has priority over the cog.
  • cgraceycgracey Posts: 14,155
    evanh wrote: »
    If the FIFO is in use I think it'll mess that up because it has priority over the cog.

    Right. It could interrupt the block transfer and cause another 9 clocks to go by before it's able to resume.
  • So we have to say...

    "As long as the writing party does SETQ+WRLONG and the reading parties do SETQ+RDLONG, all using the same Q value and hub address, and if the streamer is not running and code is beeing executed in cog or LUT RAM then you effectively get atomic reads and writes of any number of longs (limited by cog RAM size, of course)."

    Correct?
  • cgraceycgracey Posts: 14,155
    > @ManAtWork said:
    > So we have to say...
    >
    > "As long as the writing party does SETQ+WRLONG and the reading parties do SETQ+RDLONG, all using the same Q value and hub address, and if the streamer is not running and code is beeing executed in cog or LUT RAM then you effectively get atomic reads and writes of any number of longs (limited by cog RAM size, of course)."
    >
    > Correct?

    Yes.
Sign In or Register to comment.