TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Hazard Pointers in C++26

12 pointsby ibobev16 days ago

2 comments

Veserv16 days ago
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>
nynx16 days ago
It would be insane to put a system as complex as hazard pointers in the C++ standard.
评论 #43907648 未加载