Locks Not working , Need to make mutilple acces secure
Tring to implement the locks in my program to be sure i am not reading the data the same time that I am writing to the same data
so to get it startet im trying with some blinky leds . blink 2 runs form a second cog , ( this is where I would normaly measure temperture and write it to rom )
and blinking a led 5 now
blink runs from my main cog , normaly this is reading and displaying the reading , ( now blinking led 6 )
it is both are suppose to wait for each other for exlusive accec . but they just blink
think the newcog doesnt know the lock but im not getting it , would like some help .
so to get it startet im trying with some blinky leds . blink 2 runs form a second cog , ( this is where I would normaly measure temperture and write it to rom )
and blinking a led 5 now
blink runs from my main cog , normaly this is reading and displaying the reading , ( now blinking led 6 )
it is both are suppose to wait for each other for exlusive accec . but they just blink
think the newcog doesnt know the lock but im not getting it , would like some help .
VAR
byte lock
long stack1[128]
PUB Main
lock:=locknew
dira[led_5]~~ {make Led output}
dira[led_6]~~ {make Led output}
cognew(blink2 ( lock ),@stack1)
repeat
blink
PUB blink
repeat until not lockset(lock)
outa[led_6]~~
waitcnt (clkfreq+ cnt)
outa[led_6]~
lockclr(lock)
waitcnt (clkfreq / 20+ cnt)
PUB blink2 (lok)
dira[led_5]~~
repeat
repeat until not lockset(lok)
outa[led_5]~~
waitcnt (clkfreq * 3+ cnt)
outa[led_5]~
lockclr(lok)
waitcnt (clkfreq*2 + cnt)

Comments
You are not waiting for the lock. To wait for a lock you need to use code like:
PUB blink repeat repeat until not lockset(lock) ' <--- wait at this line till we get a lock outa[led_6]~~ waitcnt (clkfreq+ cnt) outa[led_6]~ lockclr(lock) waitcnt (clkfreq / 20+ cnt)See the Propeller manual page 126, and remember that in Spin, indentation is critical.
Ross.
I moddified the code , but now i only have 1 blinking led .
the idear was to get them to blink one at a time so , only the binking one may do it work , the other one needs to wait till tis finnished
. think you could help me with the last mods to get it working ,
VAR byte lock long stack1[128] PUB Main lock:=locknew dira[9..15]~~ {make Led output} cognew(blink2 ,@stack1) repeat blink PUB blink repeat repeat until not lockset(lock) ' <--- wait at this line till we get a lock outa[led_4]~~ waitcnt (clkfreq+ cnt) outa[led_4]~ lockclr(lock) waitcnt (clkfreq / 2+ cnt) PUB blink2 repeat repeat until not lockset(lock) ' <--- wait at this line till we get a lock outa[led_5]~~ waitcnt (clkfreq+ cnt) outa[led_5]~ lockclr(lock) waitcnt (clkfreq / 20+ cnt)