-
-
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
@async tasks executes simultaneously with parent task if launched with @spawn #41324
Comments
To my understanding this was never part of the contract. What is your use-case for forcing What we are actually missing right now is a |
Think about this a minute longer I think I understand your issue. Up until 1.7
and expect |
I have a few use cases in my research flow, but one that comes high to mind is running trading simulations. I can run in parallel over different days, parameters, or multiple stochastic evolutions of the simulation, however within each of said instances I have async setup code. This setup code may be doing IO or for reasons of consistency with a realtime system run as async tasks. I was very much looking forward to seeing task migration, as I can often get suboptimal scheduling currently, but I really need a way to bind tasks together in a cooperative group. I think there's opportunity to improve the API and clarity of the semantics around scheduling, and doing so now when these change are coming in would seem a good time. For everyone's safety and benefit the old APIs could maintain the old behavior, and we can move forward with a new and more expressive API that people can opt-in to get the benefits of a more flexible scheduler without being caught off guard with behavior changes. |
So one very unsatisfying "fix" would be to have
|
After verbal discussion in #multithreading (per the usual call schedule), we said that fix seems good, but that it belongs in |
That's the slack channel, is it? This fi makes it no worse than before, but makes task migration useless for most of my use cases. Where is the best place to discuss this going forward? Are there other users with more heavy / complex task usage? |
Part of the problem is that we are in the feature freeze for 1.7 and the options boiled down to: revert #40715 or do #41334. We also consider the option that we could make
Yes and a regular call on multithreading topics.
It is rather unfortunate that a single
Most use-cases I have seen a either fully |
I'll be interested to see where that design discussion goes, so I'll join slack and try to stay in the loop. Would it be correct to assume if I manually flip the sticky flag the task may later migrate? I have some control over this, in fact I don't use the standard |
If a task flips its own flag, then it will immediately be eligible for migration the next time it yields |
However if an async child task flips the parent bit, then what's required to have it migrate? Presumably it's sitting in a thread local queue at this point, since it was sticky. |
This sounds like a good idea to me. Did you guys consider decrementing at the end of child task? i.e. let p = current_task()
p.sticky += 1
@async try
f()
finally
p.sticky -= 1
end
end ? |
The issue is that this must hold true for Tasks that are created without |
If |
How about doing this inside if t.sticky > 0 || Threads.nthreads() == 1
if tid == 0
original_code = t.code
parent_task = current_task()
parent_task.sticky += 1
t.code = function wrapper_code()
try
original_code()
finally
parent_task.sticky -= 1
end
end
tid = Threads.threadid()
ccall(:jl_set_task_tid, Cvoid, (Any, Cint), t, tid-1)
end
push!(Workqueues[tid], t)
else
...
I think it'd be a good idea to minimize the API around stickiness. |
Agreed on minimizing API, although at present |
Commented on this being a potential issue in #40715, and have I believe verified it in 1.7.0-beta2.
Reproducible:
Since this is a race issue output isn't deterministic, however running this on 2 threads, I get
1.6.0:
1.7.0-beta2:
Maybe I've messed something up in my test here, it's not trivial to check these scheduler behaviors, but I think this confirms what I was concerned about in this comment: #40715 (comment)
Different
@async
tasks also execute simultaneously with one another (as they may have been launched on different threads), however I took out the detection of that to simplify the code.The text was updated successfully, but these errors were encountered: