diff --git a/Project.toml b/Project.toml index 1c9169c..f0b3cf9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "CommonDataFormat" uuid = "a9737db6-c05c-4e48-868b-6bc41491d9d9" -version = "0.4.2" +version = "0.4.3" authors = ["Beforerr and contributors"] [workspace] diff --git a/src/CommonDataFormat.jl b/src/CommonDataFormat.jl index 9f7eed8..4130c00 100644 --- a/src/CommonDataFormat.jl +++ b/src/CommonDataFormat.jl @@ -21,15 +21,20 @@ export is_record_varying return chnl end else + # First called inside `@threads`; unlocked, racing workers each build a pool and one + # deadlocks returning its decompressor to the other, already full, pool. const _decompressors = Ref{Union{Channel{Decompressor},Nothing}}(nothing) + const _decompressors_lock = ReentrantLock() function decompressors() - if _decompressors[] === nothing - n_ch = nthreads() - chnl = Channel{Decompressor}(n_ch) - foreach(i -> put!(chnl, Decompressor()), 1:n_ch) - _decompressors[] = chnl + @lock _decompressors_lock begin + if _decompressors[] === nothing + n_ch = nthreads() + chnl = Channel{Decompressor}(n_ch) + foreach(i -> put!(chnl, Decompressor()), 1:n_ch) + _decompressors[] = chnl + end + return _decompressors[] end - return _decompressors[] end __init__() = _decompressors[] = nothing end