Uh oh!
There was an error while loading. Please reload this page.
Use atomic flag for buffer memory-attribute initialization - #2216
Conversation
Store and read Buffer._mem_attrs_inited via std::atomic using acquire/release semantics to avoid races during lazy pointer memory- attribute initialization under free-threaded execution. Signed-off-by: Sebastian Berg <sebastianb@nvidia.com>
seberg
commented
Jun 15, 2026
/ok to test 7c1c215 |
This comment has been minimized.
This comment has been minimized.
leofang
left a comment
There was a problem hiding this comment.
The change seems fine to me. Though I wonder if there'd be a significant perf hit. Originally Buffer was meant to be a thin wrapper over the raw pointer, but we've grown the complexity over time.
Might be a good idea checking with @danielfrg and see if the micro benchmarks can tell us the perf difference. I dunno if/where it runs TBH.
In any case, approving. Thanks, Sebastian!
Uh oh!
There was an error while loading. Please reload this page.
seberg
commented
Jun 17, 2026
I doubt this'll even register, I think the critical sections may be measurable but still so fast that it shouldn't really matter. |
This comment has been minimized.
This comment has been minimized.
5 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Store and read
Buffer._mem_attrs_initedvia std::atomic using acquire/release semantics to avoid races during lazy pointer memory- attribute initialization under free-threaded execution.At least strictly speaking,
_mem_attrs_initedis a flag that guards access to other memory attributes.My understanding is that on ARM processors with weak memory ordering this can be a problem even beyond compiler optimizations making use of the fact that order isn't strictly guaranteed (without the light use of atomics).
I.e.:
thread1 -> init _mem_attrs
thread1 -> sets _mem_attrs_inited
thread2 -> reads _mem_attrs_inited
thread2 -> reads _mem_attrs
Does not guarantee that thread2 doesn't read the uninitialized
_mem_attrsThis is probably not sufficiently covered by pytest-run-parallel, so if desired I/we should add an explicitly threaded test for it. (Although I have doubts we'll be able to fail the test even without the changes)