Closed NHDaly closed 3 years ago
As a note, it is generally better to allocate the object on the thread that it will be used (see https://github.com/JuliaWeb/HTTP.jl/pull/704 and https://github.com/JuliaLang/julia/blob/e4fcdf5b04fd9751ce48b0afc700330475b42443/stdlib/Random/src/RNGs.jl#L369-L385 for examples).
Thanks for filing the issue and the suggestions. Feel free to make a PR, otherwise I'll try to get to this during the week.
K, this is definitely not done, but i started a PR here: https://github.com/JuliaTime/TimeZones.jl/pull/344
@omus maybe you can pick it up from there? ❤️ Please feel free to edit the PR directly.
🙏 @KristofferC thanks for the examples, that's good to see. 👍
The
TIME_ZONE_CACHE
is not currently thread safe, so parsing aTimeZone
object via the following constructor is currently a race condition, and can lead to crashes and errors:https://github.com/JuliaTime/TimeZones.jl/blob/906cea08c2ca4a5c76b12e14fb60d5df7990fbf7/src/types/timezone.jl#L1
https://github.com/JuliaTime/TimeZones.jl/blob/906cea08c2ca4a5c76b12e14fb60d5df7990fbf7/src/types/timezone.jl#L43-L47
The cache either needs to be surrounded by a lock (though this would serialize all TimeZone constructors and probably be worse than having no cache at all), or replicated via thread-local caches.
I would probably suggest a thread-local cache? But interested in other ideas! :)
Maybe just something like this?: