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

Having one coroutine exit stops the entire program. #71

Closed
BookOwl opened this issue Mar 21, 2017 · 4 comments
Closed

Having one coroutine exit stops the entire program. #71

BookOwl opened this issue Mar 21, 2017 · 4 comments
Assignees
Labels

Comments

@BookOwl
Copy link
Contributor

BookOwl commented Mar 21, 2017

For some reason whenever one of the coroutines created with this crate exit, my entire program also exits. Here is a simple test case that demonstrates the issue:

extern crate coroutine;
use coroutine::asymmetric::*;

fn main() {
    let mut c = Coroutine::spawn(move|h, data| {
        h.yield_with(0);
        h.yield_with(0);
        0
    });
    println!("{:?}", c.state());
    c.resume(0);
    println!("{:?}", c.state());
    c.resume(0);
    println!("{:?}", c.state());
    c.resume(0); // exits here
    println!("{:?}", c.state());
    println!("goodbye", );
}
@BookOwl
Copy link
Contributor Author

BookOwl commented Mar 21, 2017

Here is the log generated:

10:14:21 [TRACE] coroutine::asymmetric: [/Users/matthew/.cargo/registry/src/github.com-1ecc6299db9ec823/coroutine-0.7.0/src/asymmetric.rs:255] Coroutine `0x107800d70`: yielding to Context(0x1078005d8)
10:14:21 [TRACE] coroutine::asymmetric: [/Users/matthew/.cargo/registry/src/github.com-1ecc6299db9ec823/coroutine-0.7.0/src/asymmetric.rs:198] Coroutine `0x107800d70`: yielding to Context(0x7fff58d2cc78)
Parked
10:14:21 [TRACE] coroutine::asymmetric: [/Users/matthew/.cargo/registry/src/github.com-1ecc6299db9ec823/coroutine-0.7.0/src/asymmetric.rs:255] Coroutine `0x107800d70`: yielding to Context(0x107800348)
10:14:21 [TRACE] coroutine::asymmetric: [/Users/matthew/.cargo/registry/src/github.com-1ecc6299db9ec823/coroutine-0.7.0/src/asymmetric.rs:198] Coroutine `0x107800d70`: yielding to Context(0x7fff58d2cc78)
Parked
10:14:21 [TRACE] coroutine::asymmetric: [/Users/matthew/.cargo/registry/src/github.com-1ecc6299db9ec823/coroutine-0.7.0/src/asymmetric.rs:255] Coroutine `0x107800d70`: yielding to Context(0x107800348)
10:14:21 [TRACE] coroutine::asymmetric: [/Users/matthew/.cargo/registry/src/github.com-1ecc6299db9ec823/coroutine-0.7.0/src/asymmetric.rs:72] Coroutine `0x107800d70`: returned from callback with result 0
10:14:21 [TRACE] coroutine::asymmetric: [/Users/matthew/.cargo/registry/src/github.com-1ecc6299db9ec823/coroutine-0.7.0/src/asymmetric.rs:78] Coroutine `0x107800d70`: finished => dropping stack

@zonyitoo
Copy link
Contributor

Well, I think it just crash right there. Because the internal state of Coroutine has been destroyed after the third c.resume(0) call. So the next c.state() crashed.

@zonyitoo zonyitoo added the bug label Mar 21, 2017
@zonyitoo zonyitoo self-assigned this Mar 21, 2017
zonyitoo added a commit that referenced this issue Mar 21, 2017
@zonyitoo
Copy link
Contributor

Please try the latest commit, it should fix your issue.

@BookOwl
Copy link
Contributor Author

BookOwl commented Mar 23, 2017

thanks, it works fine now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants