[racket] Deadlock with FIFO files

From: Eric Dobson (eric.n.dobson at gmail.com)
Date: Sun Oct 26 00:06:54 EDT 2014

I'm attempting to use FIFOs as a simple IPC mechanism and I'm getting
into a deadlock. I've simplified my program to the following and am
still getting deadlocks. I believe that this shouldn't have an issues,
but I might be wrong about that. Am I doing something wrong, or might
this be a bug in the IO system? I'm running on OS X 10.9.5 if that is
relevant.

It usually gets stuck at around 10-11 thousand.


#lang racket

(define the-fifo-path "the-fifo")

(when (file-exists? the-fifo-path)
  (delete-file the-fifo-path))

(system "mkfifo the-fifo")

(thread
  (lambda ()
    (call-with-output-file* the-fifo-path #:exists 'append
      (lambda (port)
        (file-stream-buffer-mode port 'none)
        (let loop ([i 0])
          (printf "Writing ~a~n" i)
          (write i port)
          (newline port)
          (loop (add1 i)))))))

(call-with-input-file* the-fifo-path
  (lambda (port)
    (file-stream-buffer-mode port 'none)
    (let loop ()
      (displayln "Reading")
      (define v (read-line port))
      (unless (eof-object? v)
        (printf "Read ~a~n" v)
        (loop)))))

Posted on the users mailing list.