<p dir="auto">I have some code that deadlocks, I think during some phase of code generation. Here's a little test case. Not quite the same context as my code, but I think the same bug:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Threads.@threads for i in 1:1
end
no_such_function()"><pre class="notranslate">Threads<span class="pl-k">.</span><span class="pl-c1">@threads</span> <span class="pl-k">for</span> i <span class="pl-k">in</span> <span class="pl-c1">1</span><span class="pl-k">:</span><span class="pl-c1">1</span>
<span class="pl-k">end</span>
<span class="pl-c1">no_such_function</span>()</pre></div>
<p dir="auto">This should give an error of course, because <code class="notranslate">no_such_function</code> is undefined. That's what it does on julia 1.1 regardless of the number of threads, but it deadlocks for me on master if &gt;1 threads are specified. I ran a bisect which implicated this commit <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/JuliaLang/julia/commit/0136fa10d5ba6782465ea68de37acefcb548bd9c/hovercard" href="https://github.com/JuliaLang/julia/commit/0136fa10d5ba6782465ea68de37acefcb548bd9c"><tt>0136fa1</tt></a></p>
<p dir="auto">Totally confused by the segmentation fault I'm getting on dev branch. Started seeing it perhaps a couple weeks back but had a hard time getting a small test case that would reliably trigger the error.</p>
<p dir="auto">The following snippet works fine if threads are off and works v1.1 with threads on or off. For some reason importing PyCall seems important but I have no idea why (BTW: I have PyCall v1.91.2).</p>
<p dir="auto">Can anybody else reproduce this?</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Threads.nthreads() # &lt;-- 4
import PyCall
abstract type Flat end
struct X{P&lt;:Flat, T&lt;:Real}
    t::Array{T,1}  
end
function foo(x::X{P,T}) where {P&lt;:Flat, T&lt;:Real}
    v = zeros(T, size(x.t))
    Threads.@threads for i=1:length(x.t)
        v[i] = x.t[i]^2 + sin(x.t[i]) - cos(x.t[i])
    end
    return v
end
T = Float64
x = X{Flat,T}(rand(T,1000))
@time foo(x) #&lt;--- Segmentation fault"><pre class="notranslate"><code class="notranslate">Threads.nthreads() # &lt;-- 4
import PyCall
abstract type Flat end
struct X{P&lt;:Flat, T&lt;:Real}
    t::Array{T,1}  
end
function foo(x::X{P,T}) where {P&lt;:Flat, T&lt;:Real}
    v = zeros(T, size(x.t))
    Threads.@threads for i=1:length(x.t)
        v[i] = x.t[i]^2 + sin(x.t[i]) - cos(x.t[i])
    end
    return v
end
T = Float64
x = X{Flat,T}(rand(T,1000))
@time foo(x) #&lt;--- Segmentation fault
</code></pre></div>
<p dir="auto">Here is the error I get</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="julia&gt; @time foo(x) #&lt;--- Segmentation fault

  fatal: error thrown and no exception handler available.
ErrorException(&quot;concurrency violation detected&quot;)
0.203108rec_backtrace at /Users/ethananderes/Software/juliaMaster/src/stackwalk.c:94
record_backtrace at /Users/ethananderes/Software/juliaMaster/src/task.c:210
jl_throw at /Users/ethananderes/Software/juliaMaster/src/task.c:417
 seconds (error at ./error.jl:33
assert_havelock at ./condition.jl:20 [inlined]
assert_havelock at ./condition.jl:43 [inlined]
assert_havelock at ./condition.jl:67 [inlined]
notify at ./condition.jl:118
#notify#463 at ./condition.jl:116 [inlined]
notify at ./condition.jl:116 [inlined]
notify at ./condition.jl:116 [inlined]
readcb_specialized at ./stream.jl:558
jfptr_readcb_specialized_4955 at /Users/ethananderes/Software/juliaMaster/usr/lib/julia/sys.dylib (unknown line)
528.70uv_readcb at ./stream.jl:599
 kunknown function (ip: 0x1119208a4)
 allocations: 26.948 MiB, 3.00% gc time)jlcapi_uv_readcb_4173_gfthunk at /Users/ethananderes/Software/juliaMaster/usr/lib/julia/sys.dylib (unknown line)
jlcapi_uv_readcb_4173 at /Users/ethananderes/Software/juliaMaster/usr/lib/julia/sys.dylib (unknown line)

uv__read at /workspace/srcdir/libuv/src/unix/stream.c:1179
uv__stream_io at /workspace/srcdir/libuv/src/unix/stream.c:1339
uv__io_poll at /workspace/srcdir/libuv/src/unix/kqueue.c:311
uv_run at /workspace/srcdir/libuv/src/unix/core.c:361
jl_task_get_next at /Users/ethananderes/Software/juliaMaster/src/partr.c:303
poptaskref at ./task.jl:564
wait at ./task.jl:591
task_done_hook at ./task.jl:327
jl_apply at /Users/ethananderes/Software/juliaMaster/src/./julia.h:1604 [inlined]
jl_finish_task at /Users/ethananderes/Software/juliaMaster/src/task.c:167
start_task at /Users/ethananderes/Software/juliaMaster/src/task.c:593
1000-element Array{Float64,1}:

signal (11): Segmentation fault: 11
in expression starting at REPL[8]:0
Segmentation fault: 11
"><pre class="notranslate"><code class="notranslate">julia&gt; @time foo(x) #&lt;--- Segmentation fault

  fatal: error thrown and no exception handler available.
ErrorException("concurrency violation detected")
0.203108rec_backtrace at /Users/ethananderes/Software/juliaMaster/src/stackwalk.c:94
record_backtrace at /Users/ethananderes/Software/juliaMaster/src/task.c:210
jl_throw at /Users/ethananderes/Software/juliaMaster/src/task.c:417
 seconds (error at ./error.jl:33
assert_havelock at ./condition.jl:20 [inlined]
assert_havelock at ./condition.jl:43 [inlined]
assert_havelock at ./condition.jl:67 [inlined]
notify at ./condition.jl:118
#notify#463 at ./condition.jl:116 [inlined]
notify at ./condition.jl:116 [inlined]
notify at ./condition.jl:116 [inlined]
readcb_specialized at ./stream.jl:558
jfptr_readcb_specialized_4955 at /Users/ethananderes/Software/juliaMaster/usr/lib/julia/sys.dylib (unknown line)
528.70uv_readcb at ./stream.jl:599
 kunknown function (ip: 0x1119208a4)
 allocations: 26.948 MiB, 3.00% gc time)jlcapi_uv_readcb_4173_gfthunk at /Users/ethananderes/Software/juliaMaster/usr/lib/julia/sys.dylib (unknown line)
jlcapi_uv_readcb_4173 at /Users/ethananderes/Software/juliaMaster/usr/lib/julia/sys.dylib (unknown line)

uv__read at /workspace/srcdir/libuv/src/unix/stream.c:1179
uv__stream_io at /workspace/srcdir/libuv/src/unix/stream.c:1339
uv__io_poll at /workspace/srcdir/libuv/src/unix/kqueue.c:311
uv_run at /workspace/srcdir/libuv/src/unix/core.c:361
jl_task_get_next at /Users/ethananderes/Software/juliaMaster/src/partr.c:303
poptaskref at ./task.jl:564
wait at ./task.jl:591
task_done_hook at ./task.jl:327
jl_apply at /Users/ethananderes/Software/juliaMaster/src/./julia.h:1604 [inlined]
jl_finish_task at /Users/ethananderes/Software/juliaMaster/src/task.c:167
start_task at /Users/ethananderes/Software/juliaMaster/src/task.c:593
1000-element Array{Float64,1}:

signal (11): Segmentation fault: 11
in expression starting at REPL[8]:0
Segmentation fault: 11

</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="julia&gt; versioninfo()
Julia Version 1.3.0-DEV.8
Commit 20834c3176* (2019-04-12 07:18 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.5.0)
  CPU: Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 4
  JULIA_FFTW_PROVIDER = MKL"><pre class="notranslate"><code class="notranslate">julia&gt; versioninfo()
Julia Version 1.3.0-DEV.8
Commit 20834c3176* (2019-04-12 07:18 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.5.0)
  CPU: Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 4
  JULIA_FFTW_PROVIDER = MKL
</code></pre></div>