Shop OBEX P1 Docs P2 Docs Learn Events
lockset .. how do you know u got the lock? — Parallax Forums

lockset .. how do you know u got the lock?

stevenolanstevenolan Posts: 3
edited 2013-01-11 19:59 in Propeller 1
With locks, in assembler how do know you got the lock?
The documentation is really bad.

Comments

  • lonesocklonesock Posts: 917
    edited 2013-01-10 15:06
    If you specify WC with your LOCKSET, the C flag will show the "previous lock state". You can then do a IF_C JMP to loop until the lock was previously false. If the previous lock value was true, someone else already had the lock. In either case, the lock value will be true after the LOCKSET command.

    Jonathan
  • Mark_TMark_T Posts: 1,981
    edited 2013-01-10 16:01
    Its a standard spinlock - presumably the documentation assumes a certain level of knowledge of synchronization primitives?

    [edit: pun not intended, a spinlock is a standard thing in multiprocessor hardware - compare semaphore, event counter]
  • edited 2013-01-11 19:59
    I found this description of the lockset instruction. It helped me understand the logic behind using locks. Can't remember who posted it.

    "The LOCKSET instruction reads the current state of the lock bit and ALWAYS sets the lock to one. The previous state of the lock is written to the C flag. If the C flag is 0 (IF_NC) then nobody had the lock set before you, so now it's yours (and set to 1). If the C flag is 1 (IF_C) then another process already had the lock set and you should wait."
Sign In or Register to comment.