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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Barrier: Multithreading bugs are very delicate

58 点作者 l0stman将近 15 年前

5 条评论

haberman将近 15 年前
Please read the Linux documentation on memory barriers instead of this: <a href="http://lxr.linux.no/linux+v2.6.35/Documentation/memory-barriers.txt" rel="nofollow">http://lxr.linux.no/linux+v2.6.35/Documentation/memory-barri...</a><p>The Ridiculous Fish guy is clearly very smart and writes lots of interesting stuff, but this is obviously not his area of expertise, and you can't afford to learn from someone who has any confusion on the topic.<p>In his conclusion he makes what I would consider a highly misleading comparison between locks and memory barriers. He calls locks "tanks" ("powerful, slow, safe, expensive, and prone to getting you stuck"). About memory barriers he says: "Memory barriers are a faster, non-blocking, deadlock free alternative to locks. They take more thought, and aren’t always applicable, but your code’ll be faster and scale better."<p>But memory barriers aren't an alternative to locks at all. Locks let multiple threads <i>write</i> to shared memory. Memory barriers by themselves aren't very useful; most lock-free algorithms need atomic operations like compare-and-swap, which are comparable in cost to locks (indeed, locks are implemented in terms of atomic operations).
评论 #1584564 未加载
评论 #1584436 未加载
abstractbill将近 15 年前
This was a very interesting post, but to be honest it didn't make me think "I need to learn more about multithreading", it just convinced me that I need to continue to stay away from multithreading whenever at all possible [1]. Having programs run in a way that's so far away from the way you would expect <i>can't</i> be the right way to do things.<p>[1] I tend to use processes and IPC whenever I can, for example.
评论 #1584136 未加载
评论 #1584781 未加载
houseabsolute将近 15 年前
The real takeaway is:<p>- Don't write this stuff on your own.<p>- Use someone else's mutex, and someone else's non-blocking datastructure.<p>- Really, don't write your own.<p>Threading is not that hard unless you insist on leaving the safety off and aiming it at your foot.
xilun0将近 15 年前
This guy pretend that x86 is strongly ordered, while it is not...
knodi将近 15 年前
Erlang!