Open
Description
The Shared Memory Multithreading for Dart proposal outlines a number of modifications to the Dart native runtime and core libraries which would unlock interoperability use cases which currently require developers to writing additional native code.
These modifications include:
- Introduction of shared fields - static fields which are shared between all isolates in a group. In shared native memory multithreading only fields containing trivially shareable objects are allowed to be marked as shared.
- Introduction of shared isolates - each isolate group has a dedicated isolate which does not contain any isolated state. An attempt to run code in this isolate which accesses non-shared field will throw an exception.
- API extensions to
dart:ffi
:-
NativeCallable.shared
-
There might be other changes to core libraries which would help the cause but is not necessarily required:
- Helpers for atomic reads and writes in
dart:ffi
. - API extensions to
dart:isolate
-
Isolate.shared
-
Isolate.postTask
. -
Isolate.runSync
.
-
- Introduction of
dart:concurrent
.-
AtomicRef
,AtomicInt32
,AtomicInt64
-
Mutex
andCondition
.
-
These changes do not fundamentally alter Dart's isolate model - pure Dart code running in different isolates remains isolated, but introduce more straightforward way to bridge concurrency chasm between native world (which is structured around threads) and Dart (which is structured around isolates).