@@ -479,7 +479,7 @@ impl crate::Runner for Runner {
479479 tree : Tree :: root ( ) ,
480480 execution : Execution :: default ( ) ,
481481 instrumented : false ,
482- colocated : false ,
482+ on_dedicated_thread : false ,
483483 } ;
484484 let output = executor. runtime . block_on ( panicked. interrupt ( f ( context) ) ) ;
485485 gauge. dec ( ) ;
@@ -519,7 +519,7 @@ pub struct Context {
519519 tree : Arc < Tree > ,
520520 execution : Execution ,
521521 instrumented : bool ,
522- colocated : bool ,
522+ on_dedicated_thread : bool ,
523523}
524524
525525impl Clone for Context {
@@ -537,7 +537,7 @@ impl Clone for Context {
537537 tree : child,
538538 execution : Execution :: default ( ) ,
539539 instrumented : false ,
540- colocated : self . colocated ,
540+ on_dedicated_thread : self . on_dedicated_thread ,
541541 }
542542 }
543543}
@@ -583,14 +583,15 @@ impl crate::Spawner for Context {
583583 let parent = Arc :: clone ( & self . tree ) ;
584584 let past = self . execution ;
585585 let is_instrumented = self . instrumented ;
586- let was_colocated = self . colocated ;
587586 self . execution = Execution :: default ( ) ;
588587 self . instrumented = false ;
589588
590- // Set the child's colocated flag based on spawn mode
591- self . colocated = match past {
589+ // The child runs on a dedicated thread if it is spawned as dedicated
590+ // (new thread) or colocated onto an existing dedicated thread.
591+ let parent_on_dedicated = self . on_dedicated_thread ;
592+ self . on_dedicated_thread = match past {
592593 Execution :: Dedicated => true ,
593- Execution :: Colocated if was_colocated => true ,
594+ Execution :: Colocated if parent_on_dedicated => true ,
594595 _ => false ,
595596 } ;
596597
@@ -627,7 +628,7 @@ impl crate::Spawner for Context {
627628 handle. block_on ( local. run_until ( f) ) ;
628629 }
629630 } ) ;
630- } else if matches ! ( past, Execution :: Colocated ) && was_colocated {
631+ } else if matches ! ( past, Execution :: Colocated ) && parent_on_dedicated {
631632 tokio:: task:: spawn_local ( f) ;
632633 } else if matches ! ( past, Execution :: Shared ( true ) ) {
633634 executor. runtime . spawn_blocking ( {
0 commit comments