From 4f2ee94e201d7b65ea6a3f065f5514eecdfd1fd3 Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Wed, 10 Jun 2026 09:37:00 -0700 Subject: [PATCH] [vm/isolate_api] Fix thread-starting race in threading_test. Fixes https://github.com/dart-lang/sdk/issues/63526 TEST=ci Change-Id: I7e0a52d3c5a7c04c1d853f769544547758c49545 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/509541 Reviewed-by: Slava Egorov Commit-Queue: Alexander Aprelev --- tests/ffi/threading_test.dart | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/ffi/threading_test.dart b/tests/ffi/threading_test.dart index 7720b6d5394..8c36321fe18 100644 --- a/tests/ffi/threading_test.dart +++ b/tests/ffi/threading_test.dart @@ -251,11 +251,15 @@ Future testFailRunSyncOnPinnedIsolate() async { threadInfo.join(); } +@pragma('vm:shared') +bool isHelperInThreadMainWaitingLatchRunning = false; + int threadMainWaitingLatch(Pointer data) { final helper = Isolate.create(debugName: "helper"); sp.send(helper); helper.runSync(() { + isHelperInThreadMainWaitingLatchRunning = true; waitLatch(); }); print('shutting down the isolate'); @@ -269,8 +273,13 @@ Future testFailRunSyncWithTimeout() async { } final completer = Completer(); - final rp = RawReceivePort((Isolate child_isolate) { + final rp = RawReceivePort((Isolate child_isolate) async { print('received $child_isolate'); + while (!isHelperInThreadMainWaitingLatchRunning) { + // Let the thread which should do `helper.runSync` + // actually do that. + await Future.delayed(Duration(milliseconds: 10)); + } Expect.throws( () => child_isolate.runSync(() { Expect.fail("Should not run");