dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.28k stars 1.58k forks source link

☂️ Explore shared memory multithreading #55991

Open mraleph opened 5 months ago

mraleph commented 5 months ago

This is an umbrella issue for exploring possible relaxation of Dart's isolate model and introducing some variation of shared memory multithreading into Dart.

Related:

mraleph commented 4 months ago

One open question about shared everything multithreading is around the cost of barriers required to maintain memory model and type safety. Consider the following code:

class X {
  List v;
  X() : v = [];
}

@pragma('vm:shared')
X x = X();

thread1() {
  x = X();
}

thread2() {
  x.v.length;
}

We don't want read of x.v to return null (or worse - garbage), because writes of x and x.v are reordered by hardware with weak memory model.

We should experiment with adding barrier to measure the synchronization cost. We can start by adding a barrier to GenerateAllocateObjectHelper and doing a Golem run.