Shop OBEX P1 Docs P2 Docs Learn Events
LOCKSET and friends - am I missing something? — Parallax Forums

LOCKSET and friends - am I missing something?

Bill HenningBill Henning Posts: 6,445
edited 2009-06-22 23:29 in Propeller 1
I needed some locks, so I read up on LOCKNEW, LOCKSET, LOCKCLEAR and LOCKRET.

Unless I am missing something, they are no more efficient than agreeing on a hub memory location, and using something like:

waitlock  rdbyte reg,lockptr wc
  if_nc     jmp     #waitlock
              wrbyte one,lockptr

vs.

waitlock   lockset 1 wc
    if_nc    jmp #waitlock
 




If so, the only advantage to using locks is to save a couple of registers. It would be nicer if lockset would wait until it the lock was clear.

Am I missing something?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
my 6.250MHz custom Crystals now available - run your Propeller at 100MHz!
Las - Large model assembler for the Propeller (alpha version released)
Largos - a feature full nano operating system for the Propeller
www.mikronauts.com - a new blog about microcontrollers

Comments

  • KyeKye Posts: 2,200
    edited 2009-06-22 22:17
    That's about it.

    They are useful in some situations...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-06-22 22:19
    Nope, it's more than that. ... yes, you're missing something ;o) Your code does only work in exceptional cases. There is no problem as long as the two COGs are 'in sync' in terms of this loop. If COG 1 is done with rdbyte, COG2 has access to the HUB. And COG2 can read the lockptr before COG1 had the chance to write back. So, both COGs think they got the lock.

    If you translate the lock functionality to your code, the lock-instruction is doing the read and write in one cycle which makes sure that no other COG can get the lock at the same time.
  • Bill HenningBill Henning Posts: 6,445
    edited 2009-06-22 23:29
    Aha! Thanx.
    MagIO2 said...
    Nope, it's more than that. ... yes, you're missing something ;o) Your code does only work in exceptional cases. There is no problem as long as the two COGs are 'in sync' in terms of this loop. If COG 1 is done with rdbyte, COG2 has access to the HUB. And COG2 can read the lockptr before COG1 had the chance to write back. So, both COGs think they got the lock.

    If you translate the lock functionality to your code, the lock-instruction is doing the read and write in one cycle which makes sure that no other COG can get the lock at the same time.
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    my 6.250MHz custom Crystals now available - run your Propeller at 100MHz!
    Las - Large model assembler for the Propeller (alpha version released)
    Largos - a feature full nano operating system for the Propeller
    www.mikronauts.com - a new blog about microcontrollers
Sign In or Register to comment.