Shop OBEX P1 Docs P2 Docs Learn Events
if not semID := locknew ?? — Parallax Forums

if not semID := locknew ??

Roger LeeRoger Lee Posts: 339
edited 2010-05-01 03:50 in Propeller 1
RE: "The official Guide" Programming and Customizing...

Timestamp Dev (ASM) example on page 113

I'm working through this example for PASD debugger and came to this line

if not semID := locknew

1) It's a conditional
2) negative logic ?
3) assignment operation ?
4) check out a lock

What is this line doing?



PUB TestStart

  m   := 10
  s   := 59
  ms  := 999
  dt  := clkfreq/1000

  if not semID := locknew       ' check out a lock
    cognew(@entry, @m)

'{'

  dbg.start(31, 30, @entry)     ' <--- Add for debugger
  
'}'

  repeat                        ' keep the cog running

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2010-05-01 02:16
    Roger Lee said...
    What is this line doing?
    Probably not quite what was intended? It boils down to calling cognew only when the checked out lock ID is 0, for failure (-1) or lock IDs 1..7 it does nothing (but checks out a lock regardless).
  • Roger LeeRoger Lee Posts: 339
    edited 2010-05-01 02:23
    Hmmm, very interesting.

    Thanks.
  • kuronekokuroneko Posts: 3,623
    edited 2010-05-01 02:26
    Roger Lee said...
    Hmmm, very interesting.
    I don't have the book. What's the context, i.e. maybe it's supposed to work like this? Then again the consumption of locks seems a bit suspicious.

    I found something like this in the TimeStamp Object but judging by the associated comment that's completely broken.

    Post Edited (kuroneko) : 5/1/2010 2:36:41 AM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-01 03:19
    You have to think of ":=" as an operator (which it is in Spin). The assignment gets done first, then the unary operator "not" gets applied, then the "if" test is done on the final result.
  • Roger LeeRoger Lee Posts: 339
    edited 2010-05-01 03:45
    Thank you Mike,
    makes sense when you say it like that. Just what I needed.

    So, then the result is:

    check to see if a lock is available before cognew(@entry, @m)
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-05-01 03:50
    kuroneko said...
    Probably not quite what was intended? It boils down to calling cognew only when the checked out lock ID is 0, for failure (-1) or lock IDs 1..7 it does nothing (but checks out a lock regardless).
    The programmer probably meant if ! semID := locknew instead, which is true only on a successful lock acquisition.

    -Phil
Sign In or Register to comment.