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

thread::spawn with function with no return result type causes SIGSEGV #39432

Closed
KamilaBorowska opened this issue Jan 31, 2017 · 6 comments
Closed

Comments

@KamilaBorowska
Copy link
Contributor

KamilaBorowska commented Jan 31, 2017

Messages are never printed, the program just crashes.

This only happens in release mode.

What I did?

Ran following program in release mode.

use std::thread;

fn worker() -> ! {
    loop {
        println!("Printing messages");
    }
}

fn main() {
    thread::spawn(worker);
    loop {
        thread::park();
    }
}

What was expected?

Flood of "Printing messages" messages.

What happened instead.

SIGSEGV

Meta

This was confirmed to happen on stable (on IRC and in playpen), however I don't have stable installed.

rustc 1.16.0-nightly (df8debf6d 2017-01-25)
binary: rustc
commit-hash: df8debf6d9afc431adbbd8311dcaf2b70eb9762e
commit-date: 2017-01-25
host: x86_64-unknown-linux-gnu
release: 1.16.0-nightly
LLVM version: 3.9
@pmarcelll
Copy link
Contributor

This is probably #28728.

@nagisa
Copy link
Member

nagisa commented Jan 31, 2017

This is probably #28728.

It is not.

use std::thread;

fn worker() -> ! {
    panic!("woah");
}

fn main() {
    thread::spawn(worker).join().unwrap();
}

still sigsegvs. The issue here is the ! type itself.

@nagisa
Copy link
Member

nagisa commented Jan 31, 2017

More minimal:

fn worker() -> ! {
    panic!()
}

fn main() {
    std::panic::catch_unwind(worker);
}

@alexcrichton
Copy link
Member

This is due to this causing UB:

#![feature(never_type)]

fn main() {
	unsafe {
		let a = std::mem::uninitialized::<!>();
	}
}

I vaguely remember there being an issue for that but I can't recall where. The precise call to this function happens here.

@alexcrichton
Copy link
Member

This is technically not a regression apparently because this was rejected in 1.11.0 and just started faulting in 1.12.0:

fn worker() -> ! {
    panic!()
}

fn main() {
    std::panic::catch_unwind(worker);
}

@ghost
Copy link

ghost commented Feb 1, 2017

Could you fix this by changing Data<F, R> to be a union now that they exist?

frewsxcv added a commit to frewsxcv/rust that referenced this issue Feb 11, 2017
…r=alexcrichton

Change std::panicking::try::Data into a union

No longer potentially call `mem::uninitialized::<!>()`

Fixes rust-lang#39432
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants