Structured concurrency in Cangjie
Access rate limit exceeded. Please log in to continue.
Structured Concurrency in Cangjie
The following main function will always output one of
A1
A2
B
C
or
A2
A1
B
C
main() {
spawnscope {
scopedspawn {
scopedspawn {
println("A1")
}
scopedspawn {
println("A2")
}
}.get()
// ^ `get`ing the future from a `scopedspawn`
// will `get` all the futures from threads launched
// inside with `scopedspawn`
println("B")
}
// `spawnscope` ensures that all threads launched with
// `scopedspawn` are joined before leaving the scope
// so that the following print will always happen at the end,
// and the threads above will completed without being
// terminated by the program ending.
println("C")
}