1. 9
  1. 3

    I am most likely misunderstanding something here, but is it not the same as the pipe(2) system call?

    1. 4

      Pipe is an unfortunate name for something that looks more like a queue.

      1. 3

        I don’t believe pipe(2) is safe for lock-free multiple-producer/multiple-consumer use in most implementations. It can be safe in the multiple writers case; POSIX guarantees atomic writes as long as all writes to the pipe are less than PIPE_BUF size. But I don’t believe POSIX provides useful guarantees about what happens when multiple processes simultaneously read from the same pipe without locking.

        1. 2

          The only sensible behavior would be for small size reads to be atomic too. You can be assured you’ll read contiguous bytes at least. It would be extra work for the kernel to split things up.

          Generally threaded behavior with system calls seems unspecified, but works as you’d want. If three threads call accept(), only one of them gets a connection, etc.

          That said, Linux has some nonstandard relaxations, afaik. Multiple writes (from threads, or processes) to append a regular file sometimes fail to advance the file position, resulting in overwriting (lost data). (Citation needed.)

          1. 1

            Good point; it’d be interesting to test whether in practice pipe(2) can be used for this purpose on most Unixes, even without POSIX guaranteeing the right semantics. The other main difference then would be the performance assumptions; this implementation looks designed to have hundreds or thousands of simultaneous readers/writers, which pipe(2) is probably not optimized for (but I’d have to test to say for sure).

          2. 1

            I see, thank for the explanation