-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[vm] Expose Dart_{CurrentIsolate,ExitIsolate,EnterIsolate}
For applications that want to have arbitrary number of isolates call into native code that may be blocking, we expose the API functions that allows those native threads to exit an isolate before running long/blocking code. Without the ability to exit/re-enter isolate, one may experience deadlocks as we have a fixed limit on the number of concurrently executing isolates atm. In the longer term we may find a way to do this automatically with low overhead, see [0]. But since those API functions are quite stable and we already expose e.g. `Dart_{Enter,Exit}Scope`, I don't see a reason not to expose `Dart_{Enter,Exit}Isolate`. [0] Issue #51261 Issue #51254 TEST=ffi{,_2}/dl_api_exit_enter_isolate_test Change-Id: I91c772ca962fddb87919663fea07939a498fa205 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292722 Commit-Queue: Martin Kustermann <kustermann@google.com> Reviewed-by: Daco Harkes <dacoharkes@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com>
- Loading branch information
1 parent
80de916
commit a251281
Showing
5 changed files
with
97 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
// SharedObjects=ffi_test_functions | ||
|
||
import 'dart:ffi'; | ||
import 'dart:isolate'; | ||
|
||
import 'package:expect/expect.dart'; | ||
|
||
import 'dylib_utils.dart'; | ||
|
||
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions"); | ||
|
||
final initializeApi = ffiTestFunctions.lookupFunction< | ||
IntPtr Function(Pointer<Void>), | ||
int Function(Pointer<Void>)>("InitDartApiDL"); | ||
final enterBarrier = | ||
ffiTestFunctions.lookupFunction<Void Function(IntPtr), void Function(int)>( | ||
"WaitUntilNThreadsEnterBarrier"); | ||
|
||
main() async { | ||
const threadBarrierCount = 30; | ||
|
||
initializeApi(NativeApi.initializeApiDLData); | ||
|
||
final all = <Future>[]; | ||
for (int i = 0; i < threadBarrierCount; ++i) { | ||
all.add(Isolate.run(() => enterBarrier(threadBarrierCount))); | ||
} | ||
await Future.wait(all); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
// @dart = 2.9 | ||
|
||
// SharedObjects=ffi_test_functions | ||
|
||
import 'dart:ffi'; | ||
import 'dart:isolate'; | ||
|
||
import 'package:expect/expect.dart'; | ||
|
||
import 'dylib_utils.dart'; | ||
|
||
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions"); | ||
|
||
final initializeApi = ffiTestFunctions.lookupFunction< | ||
IntPtr Function(Pointer<Void>), | ||
int Function(Pointer<Void>)>("InitDartApiDL"); | ||
final enterBarrier = | ||
ffiTestFunctions.lookupFunction<Void Function(IntPtr), void Function(int)>( | ||
"WaitUntilNThreadsEnterBarrier"); | ||
|
||
main() async { | ||
const threadBarrierCount = 30; | ||
|
||
initializeApi(NativeApi.initializeApiDLData); | ||
|
||
final all = <Future>[]; | ||
for (int i = 0; i < threadBarrierCount; ++i) { | ||
all.add(Isolate.run(() => enterBarrier(threadBarrierCount))); | ||
} | ||
await Future.wait(all); | ||
} |