Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add note regarding synchronous communication between too many isolates #6182

Merged
merged 12 commits into from
Nov 8, 2024
Prev Previous commit
Next Next commit
fix typos, links
  • Loading branch information
MaryaBelanger committed Nov 7, 2024
commit a578081b303cc0220c8e00684c44d8fa654841e1
12 changes: 6 additions & 6 deletions src/content/language/concurrency.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,26 +431,26 @@ objects, so they're subject to the same limitations.
#### Synchronous blocking communication between isolates

There is a limit to the number of isolates that can run in parallel, or *synchronously*.
MaryaBelanger marked this conversation as resolved.
Show resolved Hide resolved
This limit doesn't affect the standard *asynchronous* communction between isolates
This limit doesn't affect the standard *asynchronous* communication between isolates
via messages in Dart. You can have hundreds of isolates running concurrently
and making progress. The isolates are scheduled on the CPU in round-robin fashion
and making progress. The isolates are scheduled on the CPU in round-robin fashion,
and yield to each other often.

Isolates can only communicate *synchronously* outside of pure Dart,
using C code via [FFI] to do so.
Attempts to do synchronous communication between isolates in FFI calls
Attempts to perform synchronous communication between isolates in FFI calls
MaryaBelanger marked this conversation as resolved.
Show resolved Hide resolved
over the limit may result in deadlock unless special care is taken.
The limit is not hardcoded to a particular number,
it's calculated based on the Dart VM heap size available to the Dart application.

To avoid this situation, the C code that does synchronous communication
To avoid this situation, the C code performing synchronous communication
MaryaBelanger marked this conversation as resolved.
Show resolved Hide resolved
needs to leave the current isolate before performing the blocking operation
and re-enter it before returning to Dart from the FFI call.
Read about [`Dart_EnterIsolate`] and [`Dart_ExitIsolate`] to learn more.

[FFI]: /interop/c-interop
[`Dart_EnterIsolate`]: ({{site.repo.dart.sdk}}/blob/c9a8bbd8d6024e419b5e5f26b5131285eb19cc93/runtime/include/dart_api.h#L1254)
[`Dart_ExitIsolate`]: ({{site.repo.dart.sdk}}/blob/c9a8bbd8d6024e419b5e5f26b5131285eb19cc93/runtime/include/dart_api.h#L1455)
[`Dart_EnterIsolate`]: {{site.repo.dart.sdk}}/blob/c9a8bbd8d6024e419b5e5f26b5131285eb19cc93/runtime/include/dart_api.h#L1254
[`Dart_ExitIsolate`]: {{site.repo.dart.sdk}}/blob/c9a8bbd8d6024e419b5e5f26b5131285eb19cc93/runtime/include/dart_api.h#L1455

<a id="web"></a>
## Concurrency on the web
Expand Down