-
Notifications
You must be signed in to change notification settings - Fork 11
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
The "quick fix with caveats" example is not correct #136
Comments
Thanks. Looks like the 'quick fix' is no longer so quick. @carstenbauer what do you think, should we just remove this example now that there will be an interactive thread by default? We never really wanted to encourage people to do this sort of thing in the first place anyways. |
Note that we do discuss this issues with threadids being bad two paragraphs above the section linked:
and then in the linked section we say
|
That's true, I missed the "However, this approach doesn't solve the offset issue" part. I guess the question is if there is any value at all in describing it as a "fix" then. |
Yeah. I think with the changes coming in v1.12, the value of that section is greatly reduced and we should probably just remove it. |
Yeah, I think we should remove this bit. Perhaps we should also emphasize the potential of an out of bounds error even more since that's now much more likely. |
The reason I was looking at this is because PkgEval shows a large number of packages using the naive and wrong approach and now error (with the default interactive thread). To give some examples:
I intend to open issues on these repos with the following text (happy with some help in formulating this): Likely erroneous use of
|
Yeah that looks good, except I'd maybe emphasize more that I'm a little unsure about doing that because But I still don't like it because they're very likely to not realize that the code only produces correct results if they have a static schedule, and then accidentally break it in the future when they refactor. So the alternative would be to just not describe this (anti-)pattern in the docs here. Any thoughts? |
JuliaLang/julia#57490 though (it is in the docs for example). I agree that it is probably best to emphasize the caveats with using it. |
Ah, I see. Okay, then we'll put it back in the docs but emphasize that it is the least desirable option. |
In your text you plan to post to repos that were found via PkgEval, it might be good to at also mention the problems from task migration, and say that they have to use |
minimal demo:
julia> Threads.@threads for i ∈ 1:1000
# Nested use of `@threads` is not required to encounter this bug
# but it makes it easier to replicate since it over-subscribes
# the threads, causing more task-migration
Threads.@threads for i ∈ 1:1000
tid = Threads.threadid()
yield()
if tid !== Threads.threadid()
error("you fucked up!")
end
end
end
ERROR: TaskFailedException
nested task error: TaskFailedException
nested task error: you fucked up!
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:35
[2] macro expansion
@ ./REPL[12]:10 [inlined]
[3] (::var"#508#threadsfor_fun#101"{var"#508#threadsfor_fun#98#102"{UnitRange{Int64}}})(tid::Int64; onethread::Bool)
@ Main ./threadingconstructs.jl:253
[4] #508#threadsfor_fun
@ ./threadingconstructs.jl:220 [inlined]
[5] (::Base.Threads.var"#1#2"{var"#508#threadsfor_fun#101"{var"#508#threadsfor_fun#98#102"{UnitRange{Int64}}}, Int64})()
@ Base.Threads ./threadingconstructs.jl:154
...and 7 more exceptions.
Stacktrace:
[1] threading_run(fun::var"#508#threadsfor_fun#101"{var"#508#threadsfor_fun#98#102"{UnitRange{Int64}}}, static::Bool)
@ Base.Threads ./threadingconstructs.jl:173
[2] macro expansion
@ ./threadingconstructs.jl:190 [inlined]
[3] macro expansion
@ ./REPL[12]:5 [inlined]
[4] (::var"#494#threadsfor_fun#99"{var"#494#threadsfor_fun#97#100"{UnitRange{Int64}}})(tid::Int64; onethread::Bool)
@ Main ./threadingconstructs.jl:253
[5] #494#threadsfor_fun
@ ./threadingconstructs.jl:220 [inlined]
[6] (::Base.Threads.var"#1#2"{var"#494#threadsfor_fun#99"{var"#494#threadsfor_fun#97#100"{UnitRange{Int64}}}, Int64})()
@ Base.Threads ./threadingconstructs.jl:154
...and 7 more exceptions.
Stacktrace:
[1] threading_run(fun::var"#494#threadsfor_fun#99"{var"#494#threadsfor_fun#97#100"{UnitRange{Int64}}}, static::Bool)
@ Base.Threads ./threadingconstructs.jl:173
[2] macro expansion
@ ./threadingconstructs.jl:190 [inlined]
[3] top-level scope
@ ./REPL[12]:1 |
How about adding something like
to it. |
yeah sounds good. |
The example in https://juliafolds2.github.io/OhMyThreads.jl/stable/literate/tls/tls/#The-quick-fix-(with-caveats) assumes that
threadid()
will be in the range1:nthreads()
which is not true in the presence of e.g. interactive threads. Running the example on master where there is an interactive thread by default gives:Some further examples:
This example could be changed to use
maxthreadid
which might waste some space or perhaps be removed.The text was updated successfully, but these errors were encountered: