Implement critical sections and timeslice setting cmd
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
(
|
||||
; 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)
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user