Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Concurrent-computing/Wren/concurrent-computing.wren
Normal file
19
Task/Concurrent-computing/Wren/concurrent-computing.wren
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import "random" for Random
|
||||
|
||||
var words = ["Enjoy", "Rosetta", "Code"]
|
||||
var rand = Random.new()
|
||||
for (h in 1..3) {
|
||||
var fibers = List.filled(3, null)
|
||||
for (i in 0..2) fibers[i] = Fiber.new { System.print(words[i]) }
|
||||
var called = List.filled(3, false)
|
||||
var j = 0
|
||||
while (j < 3) {
|
||||
var k = rand.int(3)
|
||||
if (!called[k]) {
|
||||
fibers[k].call()
|
||||
called[k] = true
|
||||
j = j + 1
|
||||
}
|
||||
}
|
||||
System.print()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue