Skip to content

Commit

Permalink
Fix Thread-safety of compile() emptying all caches
Browse files Browse the repository at this point in the history
  • Loading branch information
NHDaly committed Aug 19, 2021
1 parent d366236 commit 188795f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/tzdata/compile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,14 @@ function compile(tz_source::TZSource, dest_dir::AbstractString; kwargs...)
results = compile(tz_source; kwargs...)

isdir(dest_dir) || error("Destination directory doesn't exist")
empty!(_tz_cache())
# When we recompile the TimeZones from a new source, we clear all the existing cached
# TimeZone objects, so that newly constructed objects pick up the newly compiled rules.
# Since we use thread-local caches, we spawn a task on _each thread_ to clear that
# thread's local cache.
Threads.@threads for i in 1:Threads.nthreads()
@assert Threads.threadid() === i "TimeZones.TZData.compile() must be called from the main, top-level Task."
empty!(_tz_cache())
end

for (tz, class) in results
parts = split(TimeZones.name(tz), '/')
Expand Down

0 comments on commit 188795f

Please sign in to comment.