mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-15 23:46:06 +09:00
preemption proof-of-concept
This commit is contained in:
33
assets/disk1/WORKBENCH
Normal file
33
assets/disk1/WORKBENCH
Normal file
@@ -0,0 +1,33 @@
|
||||
con.move(2,1)
|
||||
|
||||
|
||||
|
||||
let prog1 = "while(1){print(1);sys.sleep(600);}"
|
||||
let prog2 = "while(1){print(2);sys.sleep(500);}"
|
||||
|
||||
let context1 = parallel.spawnNewContext()
|
||||
let context2 = parallel.spawnNewContext()
|
||||
|
||||
let runner1 = parallel.attachProgram(context1, prog1)
|
||||
let runner2 = parallel.attachProgram(context2, prog2)
|
||||
|
||||
con.move(2,1)
|
||||
parallel.launch(runner1)
|
||||
parallel.launch(runner2)
|
||||
|
||||
|
||||
let exit = false
|
||||
|
||||
while (!exit) {
|
||||
|
||||
parallel.suspend(runner1)
|
||||
parallel.suspend(runner2)
|
||||
let [y,x] = con.getyx()
|
||||
con.move(1,2)
|
||||
print(`Used mem: ${sys.getUsedMem()} ; ${Math.random()} `)
|
||||
con.move(y,x)
|
||||
parallel.resume(runner1)
|
||||
parallel.resume(runner2)
|
||||
|
||||
sys.spin()
|
||||
}
|
||||
Reference in New Issue
Block a user