File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
shuttle/src/runtime/thread Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -246,9 +246,18 @@ pub(crate) struct PooledContinuation {
246246
247247impl 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}
You can’t perform that action at this time.
0 commit comments