Skip to content

Commit 238ee4f

Browse files
committed
Account for the jobserver implicit token
Make sure we don't accidentally deadlock ourselves by acquiring too many tokens!
1 parent 990383c commit 238ee4f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/lib.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,7 @@ impl Build {
977977
// possible as soon as any compilation fails to ensure that errors get
978978
// out to the user as fast as possible.
979979
let server = jobserver();
980+
server.release_raw()?; // release our process's token which we'll reacquire in the loop
980981
let error = AtomicBool::new(false);
981982
let mut threads = Vec::new();
982983
for obj in objs {
@@ -1008,6 +1009,10 @@ impl Build {
10081009
}
10091010
}
10101011

1012+
// Reacquire our process's token before we proceed, which we released
1013+
// before entering the loop above.
1014+
server.release_raw()?;
1015+
10111016
return Ok(());
10121017

10131018
/// Shared state from the parent thread to the child thread. This
@@ -1053,7 +1058,12 @@ impl Build {
10531058
parallelism = amt;
10541059
}
10551060
}
1056-
jobserver::Client::new(parallelism).expect("failed to create jobserver")
1061+
1062+
// If we create our own jobserver then be sure to reserve one token
1063+
// for ourselves.
1064+
let client = jobserver::Client::new(parallelism).expect("failed to create jobserver");
1065+
client.acquire_raw().expect("failed to acquire initial");
1066+
return client;
10571067
}
10581068

10591069
struct JoinOnDrop(Option<thread::JoinHandle<Result<(), Error>>>);

0 commit comments

Comments
 (0)