Shop OBEX P1 Docs P2 Docs Learn Events
PropBasic - example code using locks? — Parallax Forums

PropBasic - example code using locks?

pmrobertpmrobert Posts: 675
edited 2012-10-17 05:42 in Propeller 1
I have finally given in and am asking for example PropBasic code showing use of locks between tasks. I've tried pretty much every permutation of code I could envision - to no avail. I've searched and the only clue I was able to find is that it works just like in Spini. All well and good, but the way it works in Spin seems to utilize globally visible hub variables - which do not directly exist in PropBasic. I've tried rdlong/wrlong conversions, etc., but still no go. Even a clue would be very welcome!

-Mike

Comments

  • VonSzarvasVonSzarvas Posts: 3,451
    edited 2012-10-16 23:52
    Locks do work with PropBasic. Here is a snippet from a generic debug library I use:
    ' Wait for lock
          DO
              LOCKSET 0, __param1
           LOOP UNTIL __param1 = 0
    
    ' Do something that needs to be done exclusively (ie. whilst locked!)...
    
    
    ' Release lock
          LOCKCLR 0   
    
    

    The __param1 usage here is just as a temporary variable. It could have been any unused variable.

    If you check the Propeller manual you can find how LOCKSET works, and then this should make sense. I suspect the PropBASIC manual and/or instruction-reference guide/s might also mention LOCKSET.. might be worth a look there too.

    If you are still unsure after checking the guides, feel free to reply and I will try to provide a more complete explanation or example.

    Good luck!
  • VonSzarvasVonSzarvas Posts: 3,451
    edited 2012-10-16 23:56
    .. You can find the latest PropBasic guides included in the zip file posted by Bean at this thread:

    http://forums.parallax.com/showthread.php?143050-PropBASIC-status&p=1134491&viewfull=1#post1134491

    The manual describes LOCKSET on page 56!
  • pmrobertpmrobert Posts: 675
    edited 2012-10-17 05:42
    Thanks so very much! I did examine the literature, I just could not fully comprehend the concept. Now it's all crystal clear.

    -Mike
Sign In or Register to comment.