-
Notifications
You must be signed in to change notification settings - Fork 226
Add shared native memory proposal #4515
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
base: main
Are you sure you want to change the base?
Conversation
working/333 - shared memory multithreading/shared_native_memory.md
Outdated
Show resolved
Hide resolved
working/333 - shared memory multithreading/shared_native_memory.md
Outdated
Show resolved
Hide resolved
```dart | ||
@pragma('vm:deeply-immutable') | ||
final class ScopedThreadLocal<T> { | ||
/// Creates scoped thread local value with the given [initializer] function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, but outside of isolate-group-bound callbacks, in the context of standard isolates, does ScopedThreadLocal
instance behave like a static
field? Isolates in the end can migrate from one thread to another.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that isolates can't move between threads in synchronous calls and this API is fully synchronous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will there be something that would prevent this infrastructure from being used in asynchronous context?
static Future<String> iterableToShortString(...) {
return toStringVisiting.use((toStringVisitingValue) async {
await Future.delayed(Duration(seconds: 10));
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use it. But it is not going to do anything useful because the value of the scoped thread local will reset once the synchronous execution completes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So toStringVisiting
can become unbound after await Future.delayed(Duration(seconds: 10))
(in unlikely event) of isolate switching to a different thread? Realistically we are keeping isolate/(vm)thread affinity, so switching should not happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not related to moving between threads at all. ScopedThreadLocal
are valid within the scope of synchronous execution (hence the name). So if you do stl.use(f)
or stl.with(value, f)
once synchronous execution of this expression completes stl
(e.g. use
or with
completes) is unbound.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was curious about the case when f
is asynchronous. Would that result in ScopedThreadLocal
values bound only for initial synchronous part of f
execution? In the example above - before await Future.delayed(Duration(seconds: 10));
?
Document constructors memory model
cc @alexmarkov for memory model feedback |
This extracts relevant parts of the bigger proposal into a separate proposal.
The following things have changed:
AtomicInt
class - which can be constructed as a view onPointer
s orTypedData
objects. This is a departure from the previous "zoo of extension methods" design. We should discuss if it is actually better.ScopedThreadLocal
class which should address some known problematic usages of static state in core libraries.@lrhn @mkustermann @aam can you take a look?
@aam could you give me the current state of core-library APIs (which already work from IG bound code, which you are fixing and which we will not support). I want to align on what we think is MVP here and include this into the proposal.