Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Loop until the helper thread is done
  • Loading branch information
Zoxc committed Jan 17, 2020
commit 59bf52169c22bd23ae8033488ecbba517242845d
21 changes: 12 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@

use std::env;
use std::io;
use std::panic;
use std::process::Command;
use std::sync::{Arc, Condvar, Mutex, MutexGuard};

Expand Down Expand Up @@ -447,7 +448,16 @@ impl HelperState {
// wait for a long time for a token.
lock.requests -= 1;
drop(lock);
f();

// Run `f`, but mark ourself as done if it panics.
if let Err(panic) = panic::catch_unwind(panic::AssertUnwindSafe(|| f())) {
let mut lock = self.lock();
lock.consumer_done = true;
self.cvar.notify_one();
drop(lock);
panic::resume_unwind(panic);
}

lock = self.lock();
}
lock.consumer_done = true;
Expand Down Expand Up @@ -701,14 +711,7 @@ mod imp {
// of interrupting that, so resort to `pthread_kill` as a fallback.
// This signal should interrupt any blocking `read` call with
// `io::ErrorKind::Interrupt` and cause the thread to cleanly exit.
//
// Note that we don'tdo this forever though since there's a chance
// of bugs, so only do this opportunistically to make a best effort
// at clearing ourselves up.
for _ in 0..100 {
if state.consumer_done {
break;
}
while !state.consumer_done {
unsafe {
// Ignore the return value here of `pthread_kill`,
// apparently on OSX if you kill a dead thread it will
Expand Down