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

Panic on None when joining on thread which is called yield_now #31316

Closed
zonyitoo opened this Issue Jan 31, 2016 · 5 comments

Comments

Projects
None yet
3 participants
@zonyitoo
Copy link

zonyitoo commented Jan 31, 2016

Minimal test case:

use std::thread;

fn main() {
    let h = thread::spawn(|| {
        thread::yield_now();
    });

    h.join().unwrap();
}

This piece of code will panic with output:

thread '<main>' panicked at 'called `Option::unwrap()` on a `None` value', ../src/libcore/option.rs:367
playpen: application terminated with error code 101

Tested on playpen with stable Rust.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jan 31, 2016

I can reproduce this on playpen but not locally unfortunately.

The assertion being tripped here indicates that pthread_join returned but the return value of the thread was not filled out, so this is potentially a data race as well (hence tagging with I-nominated and T-libs). This may have to do with pthread_join returning an error but us not detecting it because the assertion only happens in debug mode. A minimal reproduction of this behavior, however, does not indicate that pthread_join is returning an error.

This would probably be easier to debug if we could reproduce it somewhere where we could debug it, but I would also be happy for now just leaving the assertion in place but switching to using Mutex or something to prevent a possible data race.

@zonyitoo did you discover this through the playpen itself, or was this something that happened locally?

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jan 31, 2016

Oh wait after a little more investigation, it looks like this program exhibits similar behavior. It looks like `sched_yield causes the thread to be terminated due to playpen considering it a bad system call.

The behavior here appears to be that the thread is immediately terminated and yet pthread_join returns 0 (success). This means that in the standard library we never hit the code that stores the return value of the thread, hence the assertion being hit.

I'm removing the nominated/unsound tags as if the thread is being killed this isn't a safety issue, it seems like it's just a bug that may want a better error message.

@zonyitoo

This comment has been minimized.

Copy link
Author

zonyitoo commented Jan 31, 2016

I discovered it on playpen itself. It seems to works well on my laptop.

So it likely is a bug in playpen?

@tbu-

This comment has been minimized.

Copy link
Contributor

tbu- commented Feb 2, 2016

In some sense, yes. You could ask the playpen maintainers to add sched_yield to the list of safe system calls.

@zonyitoo

This comment has been minimized.

Copy link
Author

zonyitoo commented Feb 3, 2016

Ok, closing and going to ask playpen maintainers to fix this.

@zonyitoo zonyitoo closed this Feb 3, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.