# Multithreading cause segmentation error of deprecation warning

**URL:** <https://discourse.julialang.org/t/multithreading-cause-segmentation-error-of-deprecation-warning/38806>\
**Category:** Performance\
**Tags:** question\
**Created:** [May 5, 2020, 12:56pm UTC](https://discourse.julialang.org/t/multithreading-cause-segmentation-error-of-deprecation-warning/38806 "2020-05-05T12:56:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JiangXL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jiangxl/32/13720_2.png) [@JiangXL](https://discourse.julialang.org/u/JiangXL)\
**Post date:** [May 5, 2020, 12:56pm UTC](https://discourse.julialang.org/t/multithreading-cause-segmentation-error-of-deprecation-warning/38806/1 "2020-05-05T12:56:09Z")

</div>

Running following codes without `--depwarn=no`

```julia
using Images
img = rand(512,512);
Threads.@threads for i in 1:200
        edge,count=imhist(img)
end

```

causes Julia crash with different output, most useful should be:

```julia
┌ Error: Exception while generating log record in module Images at /home/hf/.julia/packages/Images/7IWP4/src/algorithms.jl:796
│ exception =
│ UndefRefError: access to undefined reference
│ Stacktrace:
│ [1] getindex at ./array.jl:788 [inlined]
│ [2] ht_keyindex2!(::Dict{Any,Int64}, ::Tuple{Ptr{Nothing},Symbol}) at ./dict.jl:326
│ [3] get!(::Base.var"#242#243"{Int64}, ::Dict{Any,Int64}, ::Tuple{Ptr{Nothing},Symbol}) at ./dict.jl:447
│ [4] get! at ./dict.jl:420 [inlined]
│ [5] handle_message(::Logging.ConsoleLogger, ::Base.CoreLogging.LogLevel, ::String, ::Module, ::Symbol, ::Tuple{Ptr{Nothing},Symbol}, ::String, ::Int64; maxlog::Int64, kwargs::Base.Iterators.Pairs{Symbol,Base.StackTraces.StackFrame,Tuple{Symbol},NamedTuple{(:caller,),Tuple{Base.StackTraces.StackFrame}}}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/Logging/src/ConsoleLogger.jl:101
│ [6] macro expansion at ./logging.jl:323 [inlined]
│ [7] depwarn(::String, ::Symbol) at ./deprecated.jl:80
│ [8] imhist at /home/hf/.julia/packages/Images/7IWP4/src/deprecations.jl:226 [inlined]

```

Others are:  
`free(): invalid pointer` or `segmentation error`.

**No errors occur when running with ` julia --depswarn=no`**

Since `imhist()` in `Images.jl` is deprecation of `build_hist()`, which causes depswarning. Without multithreading, depswarning only show at first time then disappear. It seems memory of depswarning be free two more times due to mutlithreading.

I don’t mean to talk `Images.jl`, but logging. Is it better for logging to detect multithreading setting?

Thanks!

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [May 5, 2020, 1:24pm UTC](https://discourse.julialang.org/t/multithreading-cause-segmentation-error-of-deprecation-warning/38806/2 "2020-05-05T13:24:29Z")

</div>

I can reproduce with the following:

```julia
$ cat depwarn-threads.jl 
function f()
    Base.depwarn("hello", :f)
    return rand()
end
function g()
    Threads.@threads for i in 1:10
        f()
    end
end
g()

```

Sometimes works, sometimes acces to undefined reference, sometimes segfault. Seems to be fixed on Jluia master though.
