Skip to content

Instantly share code, notes, and snippets.

@alexcrichton
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexcrichton/ea7a38d32c4f84ea173d to your computer and use it in GitHub Desktop.
Save alexcrichton/ea7a38d32c4f84ea173d to your computer and use it in GitHub Desktop.
#![feature(scoped)]
use std::thread;
use std::sync::mpsc::{channel, Sender, Receiver};
fn main() {
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
let _b1 = Bomb1(tx1, rx2);
let b = Box::new(4);
foo(tx2, rx1, &b);
}
fn foo(done: Sender<()>, start: Receiver<()>, val: &i32) {
let _t = thread::scoped(move || {
drop(start.recv());
println!("value at {:p} = {}", val, val);
drop(done.send(()));
});
let _b2 = Bomb2;
}
struct Bomb1(Sender<()>, Receiver<()>);
impl Drop for Bomb1 {
fn drop(&mut self) {
println!("letting the child go");
drop(self.0.send(()));
drop(self.1.recv());
println!("returning from main thread");
}
}
struct Bomb2;
impl Drop for Bomb2 {
fn drop(&mut self) {
panic!("panicking on main thread");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment