Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go coroutine design #163

Closed
bvssvni opened this issue May 14, 2016 · 0 comments
Closed

go coroutine design #163

bvssvni opened this issue May 14, 2016 · 0 comments

Comments

@bvssvni
Copy link
Member

bvssvni commented May 14, 2016

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant