Skip to content
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

repeated threads loop hangs on windows #32087

Closed
JeffBezanson opened this issue May 20, 2019 · 9 comments · Fixed by #32211
Closed

repeated threads loop hangs on windows #32087

JeffBezanson opened this issue May 20, 2019 · 9 comments · Fixed by #32211
Assignees
Labels
multithreading Base.Threads and related functionality regression Regression in behavior compared to a previous version system:windows Affects only Windows

Comments

@JeffBezanson
Copy link
Member

Calling this function on windows:

function f()
    nt = Threads.nthreads()
    for k in 1:5
        v = zeros(32 * nt)
        Threads.@threads for n in 1:nt
            for i in 1:100000000
                v[32 * n] += i
            end
        end
        @show k, v[32 .* (1:nt)]
    end
end

with JULIA_NUM_THREADS > 1 ends up hanging, using 100% of one CPU. It sometimes gets through some iterations of the outer loop first. Can anybody reproduce this? Works fine on linux.

@JeffBezanson JeffBezanson added system:windows Affects only Windows regression Regression in behavior compared to a previous version multithreading Base.Threads and related functionality labels May 20, 2019
@KristofferC
Copy link
Member

KristofferC commented May 20, 2019

Can repro on windows. On WSL it works fine.

Ctrl-C leads to

julia> f()
ERROR: InterruptException:
Stacktrace:
 [1] macro expansion at .\threadingconstructs.jl:75 [inlined]
 [2] f() at .\REPL[1]:5
 [3] top-level scope at REPL[2]:1
caused by [exception 1]
InterruptException:
Stacktrace:
 [1] process_events at .\libuv.jl:98 [inlined]
 [2] wait() at .\task.jl:593
 [3] wait(::Base.GenericCondition{Base.Threads.SpinLock}) at .\condition.jl:104
 [4] wait(::Task) at .\task.jl:191
 [5] macro expansion at .\threadingconstructs.jl:75 [inlined]
 [6] f() at .\REPL[1]:5
 [7] top-level scope at REPL[2]:1

@JeffBezanson
Copy link
Member Author

Is it possible to attach a debugger and get the stack trace for each thread?

@JeffBezanson JeffBezanson self-assigned this May 21, 2019
@JeffBezanson
Copy link
Member Author

Did that, and I basically see thread 1 spinning or blocking while trying to wait on the thread loop tasks, even though all the tasks should have finished.

@JeffBezanson
Copy link
Member Author

I also observe that sometimes when it appears to be hanging, simply attaching and detaching gdb makes it continue and make forward progress (i.e. print another line or two of output).

@JeffBezanson
Copy link
Member Author

One theory I have is that this has to do with the delivery of signals from uv_async_send. It seems to be less predictable or work differently on windows.

@JeffBezanson
Copy link
Member Author

Closed by #32109

@StefanKarpinski
Copy link
Member

Should a new issue be opened to track fixing this in a better way?

@vtjnash
Copy link
Member

vtjnash commented May 27, 2019

The PR #32029 was also expected to fix this

@JeffBezanson
Copy link
Member Author

I was hoping so, but I tried it and the problem was still there.

@vtjnash vtjnash reopened this May 31, 2019
vtjnash added a commit that referenced this issue May 31, 2019
turns off the "do not work" flag

fix #32087
@JeffBezanson JeffBezanson removed this from the 1.2 milestone Jun 2, 2019
JeffBezanson pushed a commit that referenced this issue Jun 3, 2019
turns off the "do not work" flag

fix #32087
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
multithreading Base.Threads and related functionality regression Regression in behavior compared to a previous version system:windows Affects only Windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants