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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

A Close Look at a Spinlock

99 点作者 tgymnich超过 3 年前

2 条评论

asdfasgasdgasdg超过 3 年前
One thing I was surprised to learn about spinlocks is that not all spinlocks are spinlocks! At at least one company I have worked for, spinlocks are actually just locks that are biased to spin, but still fall back to kernel-based locking and scheduling eventually. Likewise, that company&#x27;s main mutex class spins for a while before locking.<p>When I asked why the rationale was something like, &quot;If a spinlock is ever held more than such and so number of microseconds, it&#x27;s an error that it&#x27;s a spinlock and actually it should be a mutex.&quot; Instead of doing degenerate behavior in this case, they just made the spinlock actually act like a mutex.
评论 #29136047 未加载
评论 #29135519 未加载
评论 #29135441 未加载
评论 #29135641 未加载
评论 #29135210 未加载
评论 #29135187 未加载
sydthrowaway超过 3 年前
One thing I don’t get is how blocking is implemented once you have basic mutual exclusion working? Lets say you try to take the lock, but you spin, waiting for it. But say in your OS now you want the thread to go to sleep until it’s available.. how is actually implemented without spinning and using CPU?
评论 #29137312 未加载
评论 #29136209 未加载
评论 #29135205 未加载
评论 #29135223 未加载
评论 #29135247 未加载
评论 #29137358 未加载