Multithreading cause segmentation error of deprecation warning

Running following codes without --depwarn=no

using Images
img = rand(512,512);
Threads.@threads for i in 1:200

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

┌ 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?


I can reproduce with the following:

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

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