HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
wahern
cqueues
C2016–2021
wahern / cqueues

cqueues

Continuation Queues: Embeddable asynchronous networking, threading, and notification framework for Lua on Unix.

2Distinct people
5Mentions
0Explicit recommenders
282GitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

Continuation Queues: Embeddable asynchronous networking, threading, and notification framework for Lua on Unix.

GitHub

Where it is used

No documented product use has been verified yet.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

No other repository is repeatedly linked in the same discussions.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 3:03:16 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year5 dated mentions

Observed mentions: 2016-11-03 20:05:30 UTC to 2021-05-20 02:39:27 UTC.

0122016-01-01 00:00:00 UTC to 2017-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments20162017-01-01 00:00:00 UTC to 2018-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2018-01-01 00:00:00 UTC to 2019-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments20182019-01-01 00:00:00 UTC to 2020-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2020-01-01 00:00:00 UTC to 2021-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments2021

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20162016-01-01 00:00:00 UTC2017-01-01 00:00:00 UTC101
20172017-01-01 00:00:00 UTC2018-01-01 00:00:00 UTC000
20182018-01-01 00:00:00 UTC2019-01-01 00:00:00 UTC000
20192019-01-01 00:00:00 UTC2020-01-01 00:00:00 UTC101
20202020-01-01 00:00:00 UTC2021-01-01 00:00:00 UTC101
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC202

What Hacker News says

5 sources
At this point I believe ppoll has been added to every mainstream Unix except macOS. It's also been accepted for the next POSIX revision. For many years pselect on macOS didn't actually fix the race condition, notwithstanding its UNIX03 certification. pselect was just a naive wrapper around select that didn't atomically unmask signals. So I ended up having to create a kqueue-based implementation for use on macOS and stragglers like OpenBSD which at that time lacked pselect entirely. See https://github.com/wahern/cqueues/blob/87f14f9/src/cqueues.c... I can't remember if pselect has been fixed on macOS. The same approach could be used to emulate ppoll on macOS. Though epoll, kqueue, and Solaris ports are so similar that you can easily wrap all of them behind a thin shim. See https://github.com/wahern/cqueues/blob/87f14f9/src/lib/kpoll... (Ca
Read the rest
ution: it's an incomplete refactor of a similar shim I used in some non-open source code. The original code is even simpler and has seen extensive use. The refactored shim should work but is untested.) AIX is really the only mainstream Unix lacking an API w/ equivalent semantics. AIX has a better-than-poll interface, but it doesn't work anything like the others. Notably, epoll, kqueue, and Solaris ports control descriptors are all pollable in their own right, permitting you to nest different [readiness polling-based] event loop frameworks.
In File Descriptor Limits
> Async programming also allows for structured programming, where each task is an owned resource of a parent tasks, which means that lifetimes of tasks can be controlled and runaway threads can't exist You're confusing mechanism with semantics. Here's an article on how Java's Project Loom achieves structured concurrency using its new virtual threads capability: https://vorpus.org/blog/notes-on-structured-concurrency-or-g... And the article cited above that proposes the idea of nurseries for structured concurrency: https://vorpus.org/blog/notes-on-structured-concurrency-or-g... Arguably, structured concurrency as described above is easier to obtain when using threads as your underlying mechanism, because the vast majority of code is serial[1]. That there are a handful of critical regions where you want to express concurrency relationships
Read the rest
doesn't mean we have to discard threads. That's throwing the baby out with the bath water. Self-promotion: I had stumbled on the idea of "nurseries", independently and many years before the above were published. See https://github.com/wahern/cqueues It's nominally a non-blocking "threading" API for Lua. (In Lua coroutines are also called threads.) But note the plural, continuation queues. It's trivial to instantiate a queue, which is similar to a nursery. This was by design. Many cqueues projects naturally end up with a tree of thread controllers/schedulers. It doesn't work on Windows (yet) because it relies on the fact that kqueue, epoll, and Solaris Ports descriptors can be recursively polled. [1] Serial != synchronous/blocking.
In Comparison of Rust async and Linux thread context switch time and memory use
So I just reran some tests on my existing VMs and it turns out I remembered wrong. Here's the actual break down: * Solaris 11.4: .sun_path: 108; bind/connect path maximum: 1023. Length seems to be same as open. Interestingly, open path maximum seems to be 1023 (judged by trying ls -l /path/to/sock), although I always thought it was unbounded on Solaris. * MacOS 10.14: .sun_path: 104, bind/connect path maximum: 253. Length can be bigger than .sun_path but less than open path limit. * NetBSD 8.0: .sun_path: 104, bind/connect path maximum: 253. Same as MacOS. * FreeBSD 12.0: .sun_path: 104, bind/connect path maximum: 104. * OpenBSD 6.6: .sun_path: 104, bind/connect path maximum: 103 (104 - 1). * Linux 5.4: .sun_path: 108, bind/connect path maximum: 108. * AIX 7.1: .sun_path: 1023, bind/connect path maximum: 1023. Yes, .sun_path is statical
Read the rest
ly sized to 1023! And like Solaris, open path maximum seems to be 1023 (as judged by trying ls -l /path/to/socket). Thanks to Polar Home, polarhome.com, for the free AIX shell account. Note that all the above lengths are exclusive of NUL, and the passed socklen_t argument did not include a NUL terminator. For posterity: on all these systems you can still create sockets with long paths, you just have to chdir or use bindat/connectat if available. My test code confirmed as much. And AFAICT getsockname/getpeername will only return the .sun_path path (if anything) used to bind or connect, but that's a more complex topic (see https://github.com/wahern/cqueues/blob/e3af1f63/PORTING.md#g...)
In Tell HN: C Experts Panel – Ask us anything about C
> EINTR is a promise that no progress was made. If only.... on many operating systems, you shouldn't retry close on EINTR, e.g. From [linux man page](http://man7.org/linux/man-pages/man2/close.2.html): > In particular close() should not be retried after an EINTR since this may cause a reused descriptor from another thread to be closed. Worse, it's different per operating system! - HP-UX you must try again - Linux, Solaris and AIX you don't want to try again - OSX is ill-defined and hence unsafe, you should use `close$nocancel` instead of `close` and _not_ try again. Related links: - http://austingroupbugs.net/view.php?id=529 - http://alobbs.com/post/54503240599/close-and-eintr - http://www.daemonology.net/blog/2011-12-17-POSIX-close-is-br... - https://code.google.com/p/chromium/issues/detail?id=269623 - https://github.com/wahern/cqueues/i
Read the rest
In EINTR and PC Loser-Ing: The “Worse Is Better” Case Study (2011)
IMPLEMENTATION NOTES The pselect() function is implemented in the C library as a wrapper around select(). That means it's not actually compliant. pselect needs to _atomically_ unblock signals so that if any signal handlers are invoked pselect returns EINTR error. User code can't emulate the correct semantics because there's a race between unblocking (i.e. changing the signal mask), checking for signal arrival, and calling select. It's _impossible_ to fix this race without resort to pselect, or by use of system extensions like kqueue on BSD/macOS[1] or signalfd on Linux, which can be tricky. On Solaris you just have to use pselect, or resort to the so-called "pipe trick". So the fact that pselect is a wrapper around select admits that it's not conformant. It's basically useless; worse, it's dangerous because application code calli
Read the rest
ng pselect expecting there won't be a race. You can see the race with this code, which on 10.10.5 still fails. What should happen is that it exits immediately with OK. What actually happens on macOS is that its pselect wrapper unblocks the signal, which is immediately delivered. But by then we've already checked that interrupted was still 0. It then calls select, which will timeout because it won't be interrupted--the signal was already delivered. On every other platform implementing pselect (which all do it correctly), pselect will always return EINTR because the signal unmasking and delivery happens in the kernel _after_ entering select. #include <errno.h> #include <signal.h> #include <stdio.h> #include <sys/select.h> #include <unistd.h> #include <err.h> static int interrupted; static void interrupt(int signo) { interrupted = signo; } int main(void) { struct timespec timeout = { 3, 0 }; sigset_t empty, block; int n; sigemptyset(&empty); sigemptyset(&block); sigaddset(&block, SIGHUP); sigprocmask(SIG_BLOCK, &block, NULL); signal(SIGHUP, &interrupt); raise(SIGHUP); while (!interrupted) { /* * If pselect does not atomically unblock signals, pselect * will never be interrupted and we'll lose the signal until * something else wakes us up AND we remember to check even * though we never saw EINTR. */ n = pselect(0, NULL, NULL, NULL, &timeout, &empty); if (n == -1 && errno != EINTR) { err(1, "pselect"); } else if (n == 0) { errx(1, "timed out"); } } if (interrupted != SIGHUP) errx(1, "wrong signal (got %d, expected %d)", interrupted, SIGHUP); puts("OK"); return 0; } [1] FWIW, here's a correct implementation of pselect for macOS using kqueue. (https://github.com/wahern/cqueues/blob/snap-20160812/src/cqu...) The only caveat is that creating a kqueue descriptor might fail, and you don't normally expect pselect to fail with EMFILE or ENFILE; it might even make it non-compliant. Except for that caveat, it's a compliant implementation of pselect AFAICT.
In Darling – MacOS translation layer for Linux

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.