It should be possible to .join() a thread from a thread other than the one that created it
Created by: ids1024
This code works on Linux, but never terminates on Redox; the waitpid
call never terminates because it is not the parent of the thread it is waiting on.
I originally saw this issue running rustc on Redox.
use std::thread;
use std::time;
fn main() {
let child1 = thread::spawn(|| {
thread::sleep(time::Duration::from_secs(5));
});
thread::spawn(|| {
child1.join().unwrap();
println!("joined");
}).join().unwrap();
}
I don't know how this should be solved; only one copy of the JoinHandle
is possible (pthread_join
says it has undefined behavior when called from several threads, and Rust of course doesn't allow that) but it could be in a different thread than the parent.
Normally I would just send a PR for something like this, but I'm not really sure how it should be handled... I guess the logic of waitpid
should be changed so it isn't tied to the parent process? But I think that behavior is standard, for waitpid but not pthread_join...