-
Notifications
You must be signed in to change notification settings - Fork 61
Make Time Zone Cache thread-safe with lazily-allocated thread-local caches #344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
616051e
Make Time Zone Cache thread-safe with lazily-allocated thread-local c…
NHDaly d5ec435
Use default_tz_cache() in timezones.jl
NHDaly 8cfaf9f
Finish converting TIME_ZONE_CACHE to THREADLOCAL_TIME_ZONE_CACHES
NHDaly fd9af18
PR review feedback: simplify thread-local cache __init__
NHDaly 9c96685
Add multithreading thread safety unit test
NHDaly b92cd54
Apply review suggestion: src/types/timezone.jl
NHDaly e29be93
Update test/types/timezone.jl
NHDaly 6a6ebd6
Finish applying renaming from PR review comment
NHDaly 76c5f7e
Merge branch 'master' into patch-1
NHDaly d366236
Fix Pkg.build() to use _reset_tz_cache()
NHDaly 188795f
Fix Thread-safety of `compile()` emptying all caches
NHDaly 86fae9d
Add test for concurrent compile() and TimeZone construction.
NHDaly b4cfc2e
Update src/build.jl
NHDaly 5a43c22
Update src/types/timezone.jl
NHDaly bcef249
Restrict thread-safety tests to Julia 1.3+
omus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # Test that TimeZones.jl can be safely used in a multithreaded environment. | ||
| # Note that the number of threads being used cannot be changed dynamically, so | ||
| # this test file spawns a new julia process running with multiple threads. | ||
|
|
||
| using Test | ||
|
|
||
| const program = """ | ||
| using TimeZones | ||
| using Test | ||
|
|
||
| @assert Threads.nthreads() > 1 "This system does not support multiple threads, so the thread-safety tests cannot be run." | ||
|
|
||
| @testset "Multithreaded TimeZone brute force test" begin | ||
| function create_zdt(year, month, day, tz_name) | ||
| ZonedDateTime(DateTime(year, month, day), TimeZone(tz_name)) | ||
| end | ||
| function cycle_zdts() | ||
| return [ | ||
| try | ||
| create_zdt(year, month, day, tz_name) | ||
| catch e | ||
| # Ignore ZonedDateTimes that aren't valid | ||
| e isa Union{ArgumentError,AmbiguousTimeError,NonExistentTimeError} || rethrow() | ||
| nothing | ||
| end | ||
| for year in 2000:2020 | ||
| for month in 1:5 | ||
| for day in 10:15 | ||
| for tz_name in timezone_names() | ||
| ] | ||
| end | ||
|
|
||
| outputs = Channel(Inf) | ||
| @sync begin | ||
| for _ in 1:15 | ||
| Threads.@spawn begin | ||
| put!(outputs, cycle_zdts()) | ||
| end | ||
| end | ||
| end | ||
| close(outputs) | ||
|
|
||
| tzs = collect(outputs) | ||
|
|
||
| # Test that every Task produced the same result | ||
| allsame(x) = all(y -> y == first(x), x) | ||
| @test allsame(tzs) | ||
| end | ||
|
|
||
| #---------------------------------------------------- | ||
|
|
||
| @testset "Interleaved compile() and TimeZone construction" begin | ||
| @sync for i in 1:20 | ||
| if (i % 5 == 0) | ||
| TimeZones.TZData.compile() | ||
| end | ||
| Threads.@spawn begin | ||
| TimeZone("US/Eastern", TimeZones.Class(:LEGACY)) | ||
| end | ||
| end | ||
| end | ||
| """ | ||
|
|
||
| @info "Running Thread Safety tests" | ||
| @testset "Multithreaded TimeZone construction" begin | ||
| run(`$(Base.julia_cmd()) -t8 --proj -E $(program)`) | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.