Skip to content

Commit a840dc4

Browse files
dylanjwolffDylan Wolff
andauthored
reuse Initialized continuations (#224)
Co-authored-by: Dylan Wolff <wolffdy@amazon.com>
1 parent fdc2f95 commit a840dc4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

shuttle/src/runtime/thread/continuation.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,18 @@ pub(crate) struct PooledContinuation {
246246

247247
impl Drop for PooledContinuation {
248248
fn drop(&mut self) {
249-
let c = self.continuation.take().unwrap();
249+
let mut c = self.continuation.take().unwrap();
250250
if c.reusable() {
251251
self.queue.borrow_mut().push_back(c);
252+
} else if matches!(c.state, ContinuationState::Initialized) {
253+
// A continuation which has been initialized but not run cannot be immediately reused.
254+
// This is because arguments and captures may already have been moved into the function,
255+
// and thus these moved objects won't be dropped until the function itself has been
256+
// dropped. Thus we must drop the inner function before reusing it.
257+
let old = c.function.0.replace(None);
258+
c.state = ContinuationState::NotReady;
259+
drop(old);
260+
self.queue.borrow_mut().push_back(c);
252261
}
253262
}
254263
}

0 commit comments

Comments
 (0)