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.

Semaphores are surprisingly versatile (2015)

69 pointsby bubblehack3rover 2 years ago

6 comments

raphlinusover 2 years ago
Going through the comments provides another datapoint for what I have observed as an ironclad law: the first version of any code involving tricky atomics and synchronization is always wrong. Reasoning about these things is hard for human brains.<p>I strongly recommend using tools when viable. In Rust a particularly easy-to-use and effective one is loom[1]. Alloy is another good tool that scales well but requires investment. In some cases like the Vulkan memory model, Alloy files are available[2].<p>[1]: <a href="https:&#x2F;&#x2F;docs.rs&#x2F;loom&#x2F;latest&#x2F;loom&#x2F;" rel="nofollow">https:&#x2F;&#x2F;docs.rs&#x2F;loom&#x2F;latest&#x2F;loom&#x2F;</a><p>[2]: <a href="https:&#x2F;&#x2F;github.com&#x2F;KhronosGroup&#x2F;Vulkan-MemoryModel">https:&#x2F;&#x2F;github.com&#x2F;KhronosGroup&#x2F;Vulkan-MemoryModel</a>
dangover 2 years ago
Discussed at the time:<p><i>Semaphores are surprisingly versatile</i> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=9212868" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=9212868</a> - March 2015 (17 comments)
ComputerGuruover 2 years ago
There are so many more types of semaphores than most people realize, and they&#x27;re way more versatile than their humble api might make you think. I had a go at implementing Win32-style semaphores in rust and wrote up about it at length; most people coming from the posix world had never experienced the almost &quot;thread pool management&quot; levels of awesomeness you can get from such a tiny api.<p><a href="https:&#x2F;&#x2F;neosmart.net&#x2F;blog&#x2F;2022&#x2F;implementing-truly-safe-semaphores-in-rust&#x2F;" rel="nofollow">https:&#x2F;&#x2F;neosmart.net&#x2F;blog&#x2F;2022&#x2F;implementing-truly-safe-semap...</a>
评论 #34527986 未加载
评论 #34527240 未加载
评论 #34526394 未加载
marshrayover 2 years ago
Does anyone have any insight into this rationale:<p><i>For the same reason they’re absent from Boost: a preference for mutexes and condition variables. From the library maintainers’ point of view, conventional semaphore techniques are just too error prone.</i><p>The link to the Boost FAQ page from the C++ document site is 404.
评论 #34526716 未加载
评论 #34526332 未加载
scotty79over 2 years ago
In Rust there&#x27;s a thing called Condvar <a href="https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;sync&#x2F;struct.Condvar.html" rel="nofollow">https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;sync&#x2F;struct.Condvar.html</a><p>I don&#x27;t really know how it relates to semaphores but it was exactly what I needed last time when I wanted to parallelize some computation and I needed to pause starved threads and unpause them all of them only after the last one got starved and triggered generation of next data block and moved focus of computation to that new block.
评论 #34546488 未加载
epolanskiover 2 years ago
Are those similar to Scala Zio semaphores?