You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
858 B
40 lines
858 B
4 years ago
|
(
|
||
|
; This example shows the use of critical sections.
|
||
|
|
||
|
(spawn _ unsafe 'A' 'Z')
|
||
|
(spawn _ safe '0' '9')
|
||
|
(ssleep 2)
|
||
|
|
||
|
(proc unsafe start end
|
||
|
; This can be interrupted any time
|
||
|
(:x)
|
||
|
(ld r0 start)
|
||
|
(:l)
|
||
|
(msleep 5)
|
||
|
(ld @cout r0)
|
||
|
(cmp r0 end)
|
||
|
(j.eq :x)
|
||
|
(inc r0)
|
||
|
(j :l)
|
||
|
)
|
||
|
|
||
|
(proc safe start end
|
||
|
(:again)
|
||
|
(ld r0 start)
|
||
|
; The sequence will always be complete
|
||
|
(crit
|
||
|
(ld @cout ' ') ; space to make it easier to read
|
||
|
(:l)
|
||
|
(ld @cout r0)
|
||
|
(cmp r0 end)
|
||
|
(j.eq :x)
|
||
|
(inc r0)
|
||
|
(j :l)
|
||
|
(:x)
|
||
|
(ld @cout ' ') ; space to make it easier to read
|
||
|
)
|
||
|
(yield)
|
||
|
(j :again)
|
||
|
)
|
||
|
)
|