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.

Threads can infect each other with their low priority

68 pointsby Dobiasdover 5 years ago

10 comments

RossBencinaover 5 years ago
As far as I can establish with a cursory skim, the article describes priority inversion, and states:<p>&quot;OS schedulers might implement different techniques to lessen the severity of this problem, but it&#x27;s far from being solved once and for all.&quot;<p>The article fails to describe what &quot;solved once and for all&quot; might mean.<p>Given that Priority Ceiling Protocol and Priority Inheritance are two common solutions used in real-time schedulers, I would like to understand why priority inversion is not a solved problem.<p>On the other hand, I have yet to learn whether Mac OS has any synchronisation primitives that mitigate mutex priority inversion.
评论 #21750748 未加载
评论 #21751269 未加载
评论 #21754333 未加载
评论 #21752965 未加载
评论 #21750438 未加载
chaboudover 5 years ago
Solution from the article: Don&#x27;t fiddle with thread priorities.<p>Solution that works well in real life: Use lock-free (or, better still, wait-free) data structures.<p>The trick is that, for those of us in the devices and media world, and despite not always using RT schedulers, we generally need (largely) consistently prioritized performance for critical operations. For example, I actually need my device audio buffer callback to be timely to avoid displeasing gaps.<p>How have whole industries managed to deliver sellable products in these spaces without resorting to RT kernels? In many cases, careful uses of thread priorities and, yes, mutexes, have been involved.<p>This article feels like it was written by someone half-way through:<p>Junior engineer: Just use thread priority.<p>Senior engineer: No! Thread priority is a minefield.<p>Principal engineer: We&#x27;re going to carefully walk through this minefield.
评论 #21753795 未加载
评论 #21755534 未加载
评论 #21771900 未加载
jacquesmover 5 years ago
&gt; If possible, avoid headaches by just not fiddling around with thread priorities.<p>No, learn the ins and outs of the primitives of your OS. Threads are perfectly fine to run at different priorities but as soon as you start communicating between them they become a chain of sorts and if resources are exhausted (such as a queue reaching a maximum size) or if you artificially couple the threads using some kind of sync mechanism then your priorities will not what you want them to be.<p>Prioritization works well for <i>independent</i> threads, not for dependent threads, which are somewhat closer to co-routines that happen to use the thread scheduler rather than that they call each other directly.
评论 #21750819 未加载
MaximumYCombover 5 years ago
This article seems like 3 pages of my CS Operating Systems unit summarised into an article. Since I started reading Hacker News I&#x27;ve always assumed the userbase has a typical education equating to at least a CS education.<p>Am I wrong for assuming that this article seems fairly low level for the user base here? It just seems to me that if you can read this article and understand push, pop, thread priority, mutex, transitive, etc then it&#x27;s more than likely that someone has already lectured at you about the issues that can arrive with using mutexes for locking.
评论 #21751880 未加载
评论 #21750790 未加载
评论 #21753064 未加载
cryptonectorover 5 years ago
This is called priority inversion.<p>One way to deal with this is to make it so that when a low-priority thread dequeues a message from a high-priority thread then the low-priority thread temporarily inherits the client&#x27;s higher priority, then later goes back to its lower priority. The problem is identifying when to go back. Solaris doors was an IPC mechanism that did this well, but at the price of being synchronous -- when you throw asynchrony in that approach doesn&#x27;t work, and you really do want asynchrony. If you trust the low-priority threads enough you can let them pick a priority according to that of the client they are servicing at any moment.
Danieruover 5 years ago
I was hoping for a cool story of os bugs currupting threads. Instead, as others pointed out, this is just a more verbose explanation of priority inversion.<p>I would like to read the zombie injection story still.
based2over 5 years ago
<a href="https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;programming&#x2F;comments&#x2F;e7sb5p&#x2F;threads_can_infect_each_other_with_their_low&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;programming&#x2F;comments&#x2F;e7sb5p&#x2F;threads...</a>
devitover 5 years ago
Note that this is only catastrophic when using <i>realtime</i> thread priorities, i.e. thread priority kinds that cause a runnable higher priority thread to run instead of a lower priority one regardless of how much time they have been running already.<p>In general OSes, the commonly used thread priorities are not realtime, and you need admin&#x2F;root to set realtime thread priorities.<p>Also indefinite deadlock can only happen if realtime threads want to take up more CPU than available (which in particular requires to not have more cores than realtime threads), since otherwise they will eventually all be sleeping&#x2F;waiting, allowing any threads waiting on the mutex to run.
solidsover 5 years ago
Can this be resumed to “A consumer cannot be faster than the producer”?
评论 #21751554 未加载
snovv_crashover 5 years ago
Isn&#x27;t this an issue on the OS side? It should only actually lock the mutex once the scheduler returns, and not on the entrance to the function.