-
Notifications
You must be signed in to change notification settings - Fork 29
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
Detach from any threads we have attached to. #173
Conversation
e0ab587
to
c922cbe
Compare
Oh boy, this will be quite some trouble outside of simple examples (where we'll have to deal with the fact that We also have no control over dispatch deciding to start/stop threads, so we may leave lingering resources since we'd never detach some of the threads hm. I think in the long term we're going to need to write an executor, make it the global and main executor and there we'd have to control threads and this way we'd be able to detach them consistently... 🤔 We are considering offering APIs to customize the global default executors so this may be possible nicely in the future, but that's not until next Swift release hm. Meanwhile I'll think about your idea here. |
This relates to #157 – if we remove the affinity between projected objects and environments, then we can always attach a thread on demand (and register a detach destructor). I'm not sure what the right thing to do is when there are multiple VMs, but the JNI spec is quite clear that environments are pre-thread (FWIW, Android only ever has a single VM). |
Given the necessary hooks in the Swift runtime (I haven't looked too closely), we could definitely extend our AExecutor to be a concurrent executor. But whilst idiomatic, a platform-agnostic approach that uses a thread pool which attaches/detaches should be fine. The elephant in the room here though is going to be third-party libraries that use libdispatch instead of Swift concurrency. (I've already had to carefully audit the dependencies in my application to ensure that nothing calls |
Heh main.async() is a pretty funny wrinkle. Having that said, if we had proper Swift concurrency adopting libraries they'd do |
CI error appears unrelated
|
Gotta update the branch, can you do that please :) |
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 think this is okey for the time being, if we find better ways of doing this we can adjust of course.
Thanks for the contrib! |
Fixes: #172