> One posix thread blocked reading from a pipe (using posix
> open/read) won't unblock when you close the file handle from
> another thread.

Yes, it does!

Compile the two attached source files:
$ gcc -o read read.c
$ gcc -o close close.c

Create the named pipe:
$ mkfifo testfifo

In two different terminals, run "read", which will block in 
read(), then "close".

You will remark that the blocking read call is unblocked when the 
other process closes its descriptor.


As a conclusion, the behaviour that you observed with Xenomai 
pipes seems consistent with that of Linux' named pipes, except 
that in Linux read() returns 0, and not an error code as you 
observed with Xenomai.

-- 
Romain Lenglet
#include <stdio.h>
#include <fcntl.h>

#define SIZE 1024

int
main (int argc, char **argv)
{
  int desc;
  int nread;
  char buf[SIZE];
  desc = open ("./testfifo", O_WRONLY);
  if (desc == -1)
    {
      perror (argv[0]);
      return 1;
    }
  close (desc);
  return 0;
}
#include <stdio.h>
#include <fcntl.h>

#define SIZE 1024

int
main (int argc, char **argv)
{
  int desc;
  int nread;
  char buf[SIZE];
  desc = open ("./testfifo", O_RDONLY);
  if (desc == -1)
    {
      perror (argv[0]);
      return 1;
    }
  while ((nread = read (desc, buf, SIZE)) > 0)
    {
      buf[nread] = 0;
      printf ("child received \"%s\" (%d)\n", buf, nread);
    }
  if (nread == 0)
    printf ("child received 0 bytes!\n");
  if (nread == -1)
    perror (argv[0]);
  close (desc);
  return 0;
}

Reply via email to