Repository navigation
gh-159458: Fix free-threading data race in datetime strftime century normalization - #159520
Conversation
|
Thank you. |
|
Thanks @AnnaAr321 for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15. |
|
Thanks @AnnaAr321 for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
|
GH-159536 is a backport of this pull request to the 3.15 branch. |
|
GH-159537 is a backport of this pull request to the 3.14 branch. |
StanFromIreland
left a comment
There was a problem hiding this comment.
This was merged before I could review it, so a couple of notes for future PRs.
|
|
||
| @threading_helper.requires_working_threading() | ||
| class TestDatetime(unittest.TestCase): | ||
| def test_concurrent_strftime_normalize_century(self): |
There was a problem hiding this comment.
I think this test does not work in our current testing configuration, as it relies on the cache being empty, correct? In the CI job the whole suite runs in parallel threads, so by the time this test runs the cache is almost certainly already initialised...
| @@ -0,0 +1 @@ | |||
| Fix a ThreadSanitizer data race on the static cache in ``normalize_century()`` of the datetime module under the free-threaded build. | |||
There was a problem hiding this comment.
| Fix a ThreadSanitizer data race on the static cache in ``normalize_century()`` of the datetime module under the free-threaded build. | |
| Fix a data race in :meth:`datetime.date.strftime` and :meth:`datetime.datetime.strftime` on the free-threaded build. |
Please only include user-facing details in blurbs.
In
Modules/_datetimemodule.c,normalize_century()lazily initializes a function-localstatic int cache = -1;on the firststrftime()call using%Y,%G,%F, or%C. Under free-threaded builds (Py_GIL_DISABLED), concurrent initial calls tostrftime()race on reading and writingcache, triggering ThreadSanitizer data race warnings.Use
FT_ATOMIC_LOAD_INT_RELAXEDandFT_ATOMIC_STORE_INT_RELAXEDto atomically load and storecachein free-threaded builds with zero overhead in default GIL-enabled builds._datetime.normalize_century()#159458