Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created October 15, 2019 15:22
Show Gist options
  • Save rust-play/55d3844d2c0c5827bd40ec80410d386b to your computer and use it in GitHub Desktop.
Save rust-play/55d3844d2c0c5827bd40ec80410d386b to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
#![feature(unwind_attributes)]
use std::os::unix::thread::JoinHandleExt;
use libc::pthread_cancel;
struct DropGuard;
impl Drop for DropGuard {
fn drop(&mut self) {
println!("unwinding foo");
}
}
fn foo() {
let _x = DropGuard;
loop {
println!(".");
}
}
fn main() {
let handle = std::thread::spawn(foo);
std::thread::sleep(std::time::Duration::new(0, 10));
unsafe {
pthread_cancel(handle.as_pthread_t());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment