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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Lock-Free Data Structures (2004)

55 点作者 jervisfm超过 11 年前

5 条评论

taspeotis超过 11 年前
Raymond Chen had an interesting series on lock-free algorithms a while back [1].<p>[1] <a href="https://www.google.com.au/search?q=%22lock-free+algorithms%22+site%3Ablogs.msdn.com%2Fb%2Foldnewthing" rel="nofollow">https:&#x2F;&#x2F;www.google.com.au&#x2F;search?q=%22lock-free+algorithms%2...</a>
gliese1337超过 11 年前
Here&#x27;s the follow-up article: <a href="http://www.drdobbs.com/lock-free-data-structures-with-hazard-po/184401890" rel="nofollow">http:&#x2F;&#x2F;www.drdobbs.com&#x2F;lock-free-data-structures-with-hazard...</a> Which deals with ensuring deterministic destruction (and thus bounded memory use) with lock-free structures.
cmbaus超过 11 年前
I remember the article quite well, as it was passed around our office when it was first published. The author gave multiple presentations on the topic around that time.<p>There is a lot of genius in the article and references, but I will say from experience it is very easy to implement these approaches incorrectly, so unless an application requires the performance benefits provided, it is probably still a better bet to use standard locking mechanisms.
评论 #6978448 未加载
评论 #6979392 未加载
评论 #6979157 未加载
infogulch超过 11 年前
Why couldn&#x27;t the last reader delete the old map?<p>I guess the problem with this implementation is it requires <i>a</i> last reader for every write. If there are always readers, the second Update will block.<p><pre><code> &#x2F;&#x2F; infogulch&#x27;s lock-free implementation of WRRMMap template &lt;class K, class V&gt; class WRRMMap { Map&lt;K, V&gt;* pMap_, * pGC_; unsigned readers; public: V Lookup (const K&amp; k) { unsigned r while (r = readers, !CAS(&amp;readers, r, r+1)); &#x2F;&#x2F; increment readers V ret = (*pMap_) [k]; while (r = readers, !CAS(&amp;readers, r, r-1)); &#x2F;&#x2F; decrement if (r == 1 &amp;&amp; pGC_) { &#x2F;&#x2F; last reader. garbage collect delete pGC_; pGC_ = 0; } return ret; } void Update(const K&amp; k, const V&amp; v) { Map&lt;K, V&gt;* pNew = 0, * pOld; do { pOld = pMap_; delete pNew; pNew = new Map&lt;K, V&gt;(*pOld); (*pNew) [k] = v; } while (!CAS(&amp;pMap_, pOld, pNew)); &#x2F;&#x2F; DON&#x27;T delete pMap_; &#x2F;&#x2F; wait for the GC spot to be open, set it while (!CAS(&amp;pGC_, 0, pOld)); } }; </code></pre> (Meta question: ok to put this much code here?)
评论 #6978697 未加载
sbahra超过 11 年前
Also relevant and covers these topics in greater depth: <a href="http://queue.acm.org/detail.cfm?id=2492433" rel="nofollow">http:&#x2F;&#x2F;queue.acm.org&#x2F;detail.cfm?id=2492433</a> <a href="http://queue.acm.org/detail.cfm?id=2488549" rel="nofollow">http:&#x2F;&#x2F;queue.acm.org&#x2F;detail.cfm?id=2488549</a> <a href="http://queue.acm.org/detail.cfm?id=2490873" rel="nofollow">http:&#x2F;&#x2F;queue.acm.org&#x2F;detail.cfm?id=2490873</a> and <a href="http://queue.acm.org/detail.cfm?id=2513575" rel="nofollow">http:&#x2F;&#x2F;queue.acm.org&#x2F;detail.cfm?id=2513575</a>