3 ms·
> which you have no control over It's not quite that bad: UNIX has always guaranteed open() will return the lowest unused file descriptor. So in practice, it j
by jcalvinowens 3y ago
> which you have no control over
It's not quite that bad: UNIX has always guaranteed open() will return the lowest unused file descriptor. So in practice, it just limits you to 1024 total open files in the process, which in all fairness probably seemed like an absurdly large number at the time it was designed.
- klempner 3y agoAnd of course that guarantee has its own problem, namely that (especially in a multithreaded process) a use-after-close error is vastly more likely to cause corruption via a write to a newly opened file in the old file descriptor. And in all fairness, nobody was thinking of multithreading when these APIs were designed. We're lucky enough that errno mostly works as a thread local rather than a global.
- toast0 3y agoUse after close is, of course, tons of fun. But the guaranteed order also means open and accept require a per-process lock.