Skip to content

Error: 'assertion failed: libc::CloseHandle(native) != 0' if integer is too high. #13589

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

Closed
mdinger opened this issue Apr 18, 2014 · 2 comments · Fixed by #13606
Closed

Error: 'assertion failed: libc::CloseHandle(native) != 0' if integer is too high. #13589

mdinger opened this issue Apr 18, 2014 · 2 comments · Fixed by #13606

Comments

@mdinger
Copy link
Contributor

mdinger commented Apr 18, 2014

Code:

use std::io::println;

fn main() {

    for num in range(0, 100000) {
        spawn(proc() {
            for i in range(0,100000) {
                let x = i*i;
                }
        });
    }
}

Compile and run:

$ rustc hello.rs
...
$ hello.exe
task '<main>' failed at 'assertion failed: libc::CloseHandle(native) != 0', C:\b
ot\slave\dist2-win\build\src\libstd\rt\thread.rs:181

$

This works with 1,000 but not 100,000. I'm using Rust 0.10 on Win 7. I didn't try nightlies.

@lifthrasiir
Copy link
Contributor

It seems that we are currently not checking for the error of CreateThread API call in the std::rt::thread::imp::create function. Spawning too many threads causes the invalid handle that is caught by CloseHandle much later. Pretty bad.

@mdinger By the way, the default runtime (libnative) is not designed for spawning lots of tasks. Consider using libgreen for that; the runtime guide will give more information about what is a runtime and how you can switch it.

@mdinger
Copy link
Contributor Author

mdinger commented Apr 18, 2014

Thanks for the tip. I'll look into it.

alexcrichton added a commit to alexcrichton/rust that referenced this issue Apr 18, 2014
On windows, correctly check for errors when spawning threads, and on both
windows and unix handle the error more gracefully rather than printing an opaque
assertion failure.

Closes rust-lang#13589
bors added a commit that referenced this issue Apr 19, 2014
On windows, correctly check for errors when spawning threads, and on both
windows and unix handle the error more gracefully rather than printing an opaque
assertion failure.

Closes #13589
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

Successfully merging a pull request may close this issue.

2 participants