concj:基于结构化并发的多线程控制项目

Structured concurrency in Cangjie

Branch1Tags0

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")
}

Introduction

Structured concurrency in Cangjie

Customize your domain