@@ -418,6 +418,14 @@ DWORD CorUnix::InternalWaitForMultipleObjectsEx(
418418
419419 if (fNeedToBlock )
420420 {
421+ #ifdef FEATURE_SINGLE_THREADED
422+ // In single-threaded WASM, blocking would deadlock because there is no other
423+ // thread to signal the object. This is a programming error.
424+ _ASSERT_MSG (false , " Cannot block on wait in single-threaded mode\n " );
425+ pThread->SetLastError (ERROR_NOT_SUPPORTED);
426+ dwRet = WAIT_FAILED;
427+ goto WFMOExIntCleanup;
428+ #else // FEATURE_SINGLE_THREADED
421429 ThreadWakeupReason twrWakeupReason;
422430
423431 //
@@ -452,6 +460,7 @@ DWORD CorUnix::InternalWaitForMultipleObjectsEx(
452460 dwRet = WAIT_FAILED;
453461 break ;
454462 }
463+ #endif // FEATURE_SINGLE_THREADED
455464 }
456465
457466 if (!fWAll && (WAIT_OBJECT_0 == dwRet))
@@ -493,6 +502,13 @@ DWORD CorUnix::InternalSleepEx (
493502 CPalThread * pThread,
494503 DWORD dwMilliseconds)
495504{
505+ #ifdef FEATURE_SINGLE_THREADED
506+ // In single-threaded WASM, Sleep returns immediately.
507+ // There's no other thread that could make progress while we sleep.
508+ (void )pThread;
509+ (void )dwMilliseconds;
510+ return 0 ;
511+ #else // FEATURE_SINGLE_THREADED
496512 PAL_ERROR palErr = NO_ERROR;
497513 DWORD dwRet = WAIT_FAILED;
498514 int iSignaledObjIndex;
@@ -535,5 +551,6 @@ DWORD CorUnix::InternalSleepEx (
535551
536552 TRACE (" Done sleeping %u ms" , dwMilliseconds);
537553 return dwRet;
554+ #endif // FEATURE_SINGLE_THREADED
538555}
539556
0 commit comments