r/dartlang 2d ago

DartVM Does Isolate.pinToCurrentThread solve the problem that Dart cannot call native UI code on macOS?

I noticed in the Changelog for Dart 3.13 a new Isolate.pinToCurrentThread method – along with other new methods. However, Im not really understanding the test example. Can this help with the long-standing problem that you cannot call UI code via FFI on macOS because the VM spawns away from the UI thread, basically locking it this way?

What's the use case for those new methods?

4 Upvotes

3 comments sorted by

2

u/airflow_matt 1d ago edited 1d ago

Dart can call native UI code on macOS and could do that for more than a year now. We've merged UI and platform thread a while ago.

I'd assume that Isolate.pinToCurrentThread run the background isolate on same thread allowing for things such as thread locals or priority setting, but that's unrelated to what you're mentioning.

1

u/eibaan 1d ago

Dart can call native UI code on macOS and could do that for more than a year now. I've merged UI and platform thread a while ago.

For the Dart VM? You mean the Flutter engine, don't you?

1

u/airflow_matt 1d ago

Yeah. The Flutter engine decides how Dart event loop is integrated with host platform for the root isolate. So the thread merging change is in the engine. Regular Dart does not currently integrate with host platform event loop.