@@ -585,7 +585,10 @@ enum SuspendReason {
585585 NeedWork ,
586586 /// The fiber is yielding and should be resumed once other tasks have had a
587587 /// chance to run.
588- Yielding { thread : QualifiedThreadId } ,
588+ Yielding {
589+ thread : QualifiedThreadId ,
590+ skip_may_block_check : bool ,
591+ } ,
589592 /// The fiber was explicitly suspended with a call to `thread.suspend` or `thread.switch-to`.
590593 ExplicitlySuspending {
591594 thread : QualifiedThreadId ,
@@ -1557,6 +1560,9 @@ impl StoreOpaque {
15571560 } | SuspendReason :: Waiting {
15581561 skip_may_block_check: true ,
15591562 ..
1563+ } | SuspendReason :: Yielding {
1564+ skip_may_block_check: true ,
1565+ ..
15601566 }
15611567 ) || old_guest_thread
15621568 . map( |thread| self . concurrent_state_mut( ) . may_block( thread. task) )
@@ -3265,6 +3271,10 @@ impl Instance {
32653271 let reason = if yielding {
32663272 SuspendReason :: Yielding {
32673273 thread : guest_thread,
3274+ // Tell `StoreOpaque::suspend` it's okay to suspend here since
3275+ // we're handling a `thread.yield-to` call; otherwise it would
3276+ // panic if we called it in a non-blocking context.
3277+ skip_may_block_check : to_thread. is_some ( ) ,
32683278 }
32693279 } else {
32703280 SuspendReason :: ExplicitlySuspending {
@@ -3477,7 +3487,12 @@ impl Instance {
34773487 } ;
34783488 concurrent_state. push_high_priority ( item) ;
34793489
3480- store. suspend ( SuspendReason :: Yielding { thread : caller } ) ?;
3490+ store. suspend ( SuspendReason :: Yielding {
3491+ thread : caller,
3492+ // `subtask.cancel` is not allowed to be called in a
3493+ // sync context, so we cannot skip the may-block check.
3494+ skip_may_block_check : false ,
3495+ } ) ?;
34813496 break ;
34823497 }
34833498 }
0 commit comments