Skip to content

Commit beed89f

Browse files
committed
rewrite/restructure
1 parent 250255c commit beed89f

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/content/language/concurrency.md

+24-8
Original file line numberDiff line numberDiff line change
@@ -398,14 +398,6 @@ isolate, it will remain untouched in the main isolate. This is how isolates are
398398
meant to function, and it's important to keep in mind when you’re considering
399399
using isolates.
400400

401-
#### Synchronous blocking communication between isolates
402-
403-
There is a limit to the number of isolates running in parallel:
404-
405-
- The limit is not hardcoded to a particular number, it is calculated based on the Dart VM heap size available to the Dart application, can be considered to be between 8 and 32 depending on the platform.
406-
- This limit doesn't affect asynchronous communction between isolates via messages - you can have hundreds of isolates running and making progress. The isolates are scheduled on the CPU in round-robin fashion and yield to each other often.
407-
- Attempts to do *synchronous* communication between isolates over the limit though may result in a deadlock unless special care is taken (the C code that does synchronous communication would need to leave the current isolate before it blocks and re-enter it before returning to dart, see [`Dart_EnterIsolate`]({{site.repo.dart.sdk}}/blob/c9a8bbd8d6024e419b5e5f26b5131285eb19cc93/runtime/include/dart_api.h#L1254) and [`Dart_ExitIsolate`]({{site.repo.dart.sdk}}/blob/c9a8bbd8d6024e419b5e5f26b5131285eb19cc93/runtime/include/dart_api.h#L1455).
408-
409401
#### Message types
410402

411403
Messages sent via [`SendPort`][]
@@ -436,6 +428,30 @@ objects, so they're subject to the same limitations.
436428
[`Pointer`]: {{site.dart-api}}/{{site.sdkInfo.channel}}/dart-ffi/Pointer-class.html
437429
[`UserTag`]: {{site.dart-api}}/{{site.sdkInfo.channel}}/dart-developer/UserTag-class.html
438430

431+
#### Synchronous blocking communication between isolates
432+
433+
There is a limit to the number of isolates that can run in parallel, or *synchronously*.
434+
This limit doesn't affect the standard *asynchronous* communction between isolates
435+
via messages in Dart. You can have hundreds of isolates running concurrently
436+
and making progress. The isolates are scheduled on the CPU in round-robin fashion
437+
and yield to each other often.
438+
439+
Isolates can only communicate *synchronously* outside of pure Dart,
440+
using C code via [FFI] to do so.
441+
Attempts to do synchronous communication between isolates in FFI calls
442+
over the limit may result in deadlock unless special care is taken.
443+
The limit is not hardcoded to a particular number,
444+
it's calculated based on the Dart VM heap size available to the Dart application.
445+
446+
To avoid this situation, the C code that does synchronous communication
447+
needs to leave the current isolate before performing the blocking operation
448+
and re-enter it before returning to Dart from the FFI call.
449+
Read about [`Dart_EnterIsolate`] and [`Dart_ExitIsolate`] to learn more.
450+
451+
[FFI]: /interop/c-interop
452+
[`Dart_EnterIsolate`]: ({{site.repo.dart.sdk}}/blob/c9a8bbd8d6024e419b5e5f26b5131285eb19cc93/runtime/include/dart_api.h#L1254)
453+
[`Dart_ExitIsolate`]: ({{site.repo.dart.sdk}}/blob/c9a8bbd8d6024e419b5e5f26b5131285eb19cc93/runtime/include/dart_api.h#L1455)
454+
439455
<a id="web"></a>
440456
## Concurrency on the web
441457

0 commit comments

Comments
 (0)