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

Potential saftey issue #8

Closed
bbatha opened this issue Sep 23, 2015 · 5 comments
Closed

Potential saftey issue #8

bbatha opened this issue Sep 23, 2015 · 5 comments

Comments

@bbatha
Copy link

bbatha commented Sep 23, 2015

Using the following code I am able to reliably corrupt data in foo in rust nightly rustc 1.5.0-nightly (b2f379cdc 2015-09-23)

extern crate scoped_threadpool;
use scoped_threadpool::{Pool, Scope};

#[derive(Debug)]
pub struct RefOwner<'a>(&'a str);

pub struct ScopeRef<'a, 'pool, 'scope> where 'pool: 'scope, 'scope: 'a {
    scope: &'a Scope<'pool, 'scope>,
}

impl<'a, 'pool, 'scope> ScopeRef<'a, 'pool, 'scope> {
    pub fn new(scope: &'a Scope<'pool, 'scope>) -> ScopeRef<'a, 'pool, 'scope> {
        ScopeRef { scope: scope }
    }

    pub fn execute<'b: 'pool>(&self, ref_owner: &'b RefOwner) -> String {
        self.scope.execute(move || {
            println!("Got: {}", ref_owner.0);
        });
        ref_owner.0.to_owned()
    }
}

#[test]
fn it_works() {
    let foo = "foo".to_owned();
    let mut pool = Pool::new(2);

    pool.scoped(|scope| {
        let ref_owner= RefOwner(&foo);
        let scope_ref = ScopeRef::new(scope);
        let result = scope_ref.execute(&ref_owner);
        assert_eq!(foo, result);
    });
}
     Running target/debug/pool_problems-5eb09be270cfb456

running 1 test
Got: H
test it_works ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured

   Doc-tests pool_problems

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
@bbatha
Copy link
Author

bbatha commented Sep 23, 2015

Using move |scope| { ... } does not fix the error either and causes the process to crash:

running 1 test
Process didn't exit successfully: `/home/user/bbatha/experiments/pool_problems/target/debug/pool_problems-5eb09be270cfb456` (signal: 11)

@bstrie
Copy link

bstrie commented Oct 30, 2015

Is this because of some unsafe code in scoped_threadpool, or is this a soundness bug in Rust?

@bbatha
Copy link
Author

bbatha commented Nov 1, 2015

This is a soundness bug in rust see rust-lang/rust#28609

@bstrie
Copy link

bstrie commented Nov 1, 2015

@bbatha 28609 appears to be closed, does this still reproduce for you? We should be able to either close this bug or reopen that one.

@bbatha
Copy link
Author

bbatha commented Nov 2, 2015

Looks fixed in 1.4 through nightly.

@bbatha bbatha closed this as completed Nov 2, 2015
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

2 participants