Shop OBEX P1 Docs P2 Docs Learn Events
Programming advice for exclusive resource locking — Parallax Forums

Programming advice for exclusive resource locking

I am looking for the best way to exclusively lock a hardware resource. My specific use case is a wiznet Ethernet chip. I know in the past on the P1, a single COG would be dedicated to communication with such a device and all information would pass through a command register in Hub RAM. All other resources would wait for the command register to clear. Since only one cog could access the Hub at a time, that worked fine for the P1. I am concerned that is not the case for the P2, as all cogs can access the hub at once. I need to be able to perform a mutex type operation. I was thinking that the locks (that I have never seen used in the wild on the P1) would be a good facility for this type of operation.

Your comments are appreciated.

Thanks,
Terry

Comments

  • JonnyMacJonnyMac Posts: 9,104
    edited 2022-01-07 02:58

    To be clear, the cogs of the P2 cannot access the same address in hub RAM at the same time. Using a lock is probably the best way to go when you need to protect more than a single long. I only ever used locks once with the P1, and looking at the P2 docs they seem a little easier to use. I knocked together a quick demo to try them; maybe it will help. The key is acquiring a lock, then sharing the lock ID with the cogs that may need exclusive access to specific resources.

  • evanhevanh Posts: 15,915
    edited 2022-01-07 11:50

    An adjacent cog can simultaneously access an adjacent hub address, or any multiple of eight offset from the adjacent address.

    PS: Longword granular addresses that is.

Sign In or Register to comment.