Skip to content

Receive::recv() can't be used while dropping a value in thread local #24318

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
carllerche opened this issue Apr 11, 2015 · 2 comments
Closed
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@carllerche
Copy link
Member

Related to #24313, Receive::recv() accesses thread::current() which cannot be called when a thread local is being dropped

@apasel422
Copy link
Contributor

Is this referring to std::sync::mpsc::Receiver::recv?

@steveklabnik steveklabnik added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed A-libs labels Mar 24, 2017
@Mark-Simulacrum
Copy link
Member

I attempted to reproduce with Receiver::recv, but was unable to, so I'm going to close. If this is still a problem, please provide a code example we can utilize for testing.

use std::thread;
use std::sync::mpsc;

struct Handle {
    x: mpsc::Receiver<i32>,
    s: mpsc::Sender<i32>,
}

impl Drop for Handle {
    fn drop(&mut self) {
        println!("{:?}", self.x.recv().unwrap());
        println!("{:?}", self.x.recv().unwrap());
    }
}

thread_local!(static HANDLE: Handle = new_handle());

fn new_handle() -> Handle {
    let (s, r) = mpsc::channel();
    s.send(10).unwrap();
    Handle { x: r, s: s, }
}

pub fn main() {
    let _s = thread::spawn(|| {
        HANDLE.with(|h| {
            h.s.send(15).unwrap();
        });
    });

    _s.join().unwrap();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants