-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Create a Base.root_task method and document it #35726
base: master
Are you sure you want to change the base?
Conversation
538368e
to
a287eb3
Compare
I'm not sure we actually want to have this as a public API. If the root task is a special resource, then it'll need to be shared by all packages, so I expect we'd want to reserve it for the system to run a specialized event loop. Then the API might be something like |
I agree that the root Task is a special resource, and that such a facility such as Exposing a reference to the root task in the public API does not compromise its status as as special resource or prevent it from being shared by all packages. However, having a reference is necessary so that
|
True, but it will compromise our ability to supply a different, more intrinsically sharable or useful API in the future. Also, just getting a reference to the root task really isn't very useful by itself: it doesn't imply that you have a way to run code on that task or otherwise use it as a resource for doing anything useful!
But this doesn't allow you to run code that you'd like. It just schedules the root task for whatever code the root task happens to be running already. For it to be actually useful, the system must either guarantee that the root task is the task which runs user code at startup, or is otherwise left in a waiting state, ready to run some user-defined function. In both cases, it's about having a way to run given code on the task, not having a reference to the task data structure. So how do we move forward? I think the best way to take action right now is to prototype a shared event loop for the root task in a package, relying on the current implementation detail of which task runs which code at system initialization in order to steal control of the computation which the root task is running. In the longer term this might turn into some official API in Base for freeing up the root task as necessary. |
Is It may also be something useful even if we |
@tkf https://github.com/mkitti/JavaCall.jl/blame/master/src/jvm.jl#L171 Perhaps it should take an optional isroottask( task::Task = current_task() ) = Base.roottask === task |
I'm ok with So Given that the test you want is very implementation-specific, I don't see what the problem is with reaching into the implementation and just doing the |
It may be partially my "fault" as the first version of the "public API" PR #35715 (which may be a part of the cause behind this PR) used very strict wording. If so, I think this PR is good feedback to #35715. The reality of software is that implementation details leak sometimes (often?) and it's still useful to rely on it and build a stable interface. |
Yes! All I'm arguing here is that, in its current form, Therefore, I'm arguing that Undoubtedly this means JavaCall will need to rely on implementation detail of |
The actual question is: "Base, are we running on a valid stack where the dynamic library I just loaded installed a signal handler?" Currently, the answer is yes if:
It is not clear to me that this is necessarily specific to embedding Java. |
I was under the impression it was more complicated than this. Has the following situation changed? |
With
Confusingly, It is very buggy on x86 Windows: |
I created a generic worker loop here with basic functionality: https://github.com/mkitti/TaskWorkers.jl Much to do still. Comments welcome. |
Since Qt version 6.5, this is no longer JavaCall-specific, but the same issue also affects QML.jl. There, too, as a fix we need to determine if Julia code is running on the root task (also because of the stack differences between tasks). |
Currently, the constant
Base.roottask
is not documented as part of the public API per #35715. The closest API method isBase.current_task()
.Rather than documenting
Base.roottask
I suggest creatingBase.root_task()
whose implementation could change further down the road if needed. The name is consistent with the existingBase.current_task()
.Currently the implementation just returns
Base.roottask
. Alternatively, this could calljl_get_root_task
, but more work might be needed to expose it.Root
Task
detection is currently used by JavaCall.jl to detect if initialization is occurring on the rootTask
since otherwise a segmentation fault would occur ifJULIA_COPY_STACKS
were not set to 1 or "yes".Root
Task
detection may be needed to implement a work around for usingJavaCall
from@async
per @vtjnash and @c42f : #35048 (comment) #35048 (comment)