8000 `go` coroutine design · Issue #163 · PistonDevelopers/dyon · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
go coroutine design #163
Closed
Closed
@bvssvni

Description

@bvssvni

Dyon uses the go keyword to create a concurrent coroutine, similar to Go, but with the difference that Dyon uses the return value.

Example:

fn foo() -> str {
    sleep(1.0)
    return "done"
}

fn main() {
    foo_thread := go foo()
    sleep(0.5)
    val := join(thread: foo_thread)
    if is_err(val) {
        // An error happened when running the thread
        println(unwrap_err(val))
    } else {
        // Prints `done`
        println(unwrap(val))
    }
}

To provide thread safety:

  1. Arguments are evaluated on the same stack
  2. Arguments are deep cloned over to the new run-time's stack
  3. Creating a fake AST call using expression references to the deep cloned arguments
  4. The thread evaluates the fake AST call on a new thread
  5. The remaining value on the new stack is the result
  6. The new result is deep cloned

Rules:

  • go foo() requires -> on the function foo
  • go foo(a, b) must have no lifetimes on arguments of foo, because the evaluated arguments are ordered by the call and do not necessarily have the same order in the lifetime check

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0