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.

The perils of pause(2) (2023)

60 pointsby g0xA52A2Aover 1 year ago

5 comments

zokierover 1 year ago
Is there any case where anything remotely related to signals is not full of perils? UNIX has plenty of rough edges, but signals must be one of the worst..
评论 #39589723 未加载
评论 #39588746 未加载
unilynxover 1 year ago
A much cleaner and portable solution to the races triggered by duplicated and early signals is to set up a pipe and have signal handlers write the signal number to that pipe.<p>A write syscall is permitted in a signal handler and now you can (p)select&#x2F;poll the signals like any other file descriptor
评论 #39587779 未加载
评论 #39588004 未加载
评论 #39588383 未加载
userbinatorover 1 year ago
This seems like another instance of the same general race condition often referred to as the lost&#x2F;missed wakeup problem.
ajrossover 1 year ago
This isn&#x27;t really a signals problem. This is a fundamentally racy API. Any decision of the form &quot;go to sleep until this condition is true&quot; can&#x27;t be done reliably unless the code that decides &quot;this condition&quot; is atomic with respect to the entrance to the sleep state. That is, if the condition might change after you&#x27;ve decided it&#x27;s false but before you suspend, you might never wake up.<p>There are lots of solutions to this. Synchronizing along a &quot;queue&quot; a-la file descriptors or semaphores is the most common. The generalization of this &quot;suspend until&quot; problem is captured by the &quot;condition variable&quot; abstraction, which combines the sleep with a lock that provides mutual exclusion and can be released atomically on suspend.<p>But the pause() system call didn&#x27;t understand any of that, so it&#x27;s unresolvably buggy without some extra layer somewhere to act as a backstop and wake up incorrectly-sleeping processes.
评论 #39593464 未加载
majkeover 1 year ago
sigprocmask is a neat solution, but requires a syscall. Would it be theoretically possible to share the signal mask between the userspace and the kernel in no-cost way? I&#x27;m thinking vDSO style, mmaped var.<p>This could have big implications, for example most classic coroutine implementations using setjmp do some procmask dance.