TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Hazard Pointers in C++26

12 点作者 ibobev19 天前

2 条评论

Veserv19 天前
I do not understand how the implementation [1] and claimed performance make any sense.<p>In try_protect() (page 11) they only issue a load with acquire semantics (L-LS after load). The hazard pointer store, which is the actual guard, is not obviously ordered with respect to the post-acquire body using a S-LS. As such, the core, A, is allowed to reorder the store to the hazard pointer until after A has &quot;acquired&quot; and begun using the contained data which means any other core, X, attempting to reclaim that data can observe that the hazard pointer is NULL and thus can be reclaimed in that window even though the A has already determined that it is has &quot;acquired&quot; ownership and thus believes no other core can reclaim it.<p>I am not familiar with the shenanigans of modern C++ atomics, so maybe there is some implied ordering or atomics occurring in that code guaranteeing that the guarding store is atomically dependent on the load such that the acquire barrier is adequate? Otherwise that is just plain incorrect.<p>If it is incorrect, then they would require a S-LS barrier following the protecting store which is a full barrier on x86-64 and AArch64 which usually has performance more on the order of a uncontended atomic (~10-100 ns) rather than 1 ns. That lends further support for the concept that it is incorrect since the claimed performance is only possible if the hazard pointer was set with just a bare, unordered store with no atomics (even uncontended) anywhere in that code path.<p>[1] <a href="https:&#x2F;&#x2F;www.open-std.org&#x2F;jtc1&#x2F;sc22&#x2F;wg21&#x2F;docs&#x2F;papers&#x2F;2023&#x2F;p2530r3.pdf" rel="nofollow">https:&#x2F;&#x2F;www.open-std.org&#x2F;jtc1&#x2F;sc22&#x2F;wg21&#x2F;docs&#x2F;papers&#x2F;2023&#x2F;p25...</a>
nynx19 天前
It would be insane to put a system as complex as hazard pointers in the C++ standard.
评论 #43907648 未加载