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

executed tasks are leaked (testcase) #16

Open
njaard opened this issue Nov 16, 2017 · 7 comments
Open

executed tasks are leaked (testcase) #16

njaard opened this issue Nov 16, 2017 · 7 comments

Comments

@njaard
Copy link

njaard commented Nov 16, 2017

the c objects are never cleaned up even after the drop, which means that every proram that uses scoped-threadpool-rs leaks memory.

#[test]
fn no_leak() {
    let counters = ::std::sync::Arc::new(());

    let mut pool = Pool::new(4);
    pool.scoped(|scoped| {
        let c = ::std::sync::Arc::clone(&counters);
        scoped.execute(move || {
            let _c = c;
            ::std::thread::sleep(::std::time::Duration::from_millis(100));
        });
    });
    drop(pool);
    assert_eq!(::std::sync::Arc::strong_count(&counters), 1);
}
@mikeyhew
Copy link

but counters itself is a strong reference, so as long as it is alive, shouldn't the strong count be 1? If there was actually a leak, strong_count(&counters) would return 2: https://play.rust-lang.org/?gist=cc32e9dae811e8f0d397a31c004ff2c8

@njaard
Copy link
Author

njaard commented Nov 26, 2017

Well, yes, the test fails because the strong count is not 1.

@birkenfeld
Copy link

Works fine (test passes) for me (amd64 Linux; nightly and stable Rust; v0.1.8 of this crate). What configuration fails for you? Maybe it's a Rust or LLVM bug?

@mikeyhew
Copy link

@njaard

Well, yes, the test fails because the strong count is not 1.

Oh... I assumed you were using assert_eq to show that the strong count was 1. Silly me :)

@mikeyhew
Copy link

The test passes for me on the Playground: https://play.rust-lang.org/?gist=cedcfab5c332a5a58f61fb0d78389593&version=nightly

@Kimundi
Copy link
Owner

Kimundi commented Feb 20, 2018

Seems the test still passes - @njaard in what situation did you observe a assertion failure?

@Boscop
Copy link

Boscop commented Apr 10, 2020

Any update on this? :)

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

5 participants