Received: from SOUTH-STATION-ANNEX.MIT.EDU by po7.MIT.EDU (5.61/4.7) id AA01835; Thu, 14 Mar 96 16:13:07 EST
Received: from colgate.edu by MIT.EDU with SMTP
	id AA08148; Thu, 14 Mar 96 16:12:19 EST
Received: from CENTER.COLGATE.EDU by CENTER.COLGATE.EDU (PMDF V4.3-10 #6592)
 id <01I2C2A875E899ZV32@CENTER.COLGATE.EDU>; Thu,
 14 Mar 1996 16:10:11 -0500 (EST)
Date: Thu, 14 Mar 1996 16:10:11 -0500 (EST)
From: KRSNA CONSCIOUSNESS NOW <JWILSON@CENTER.COLGATE.EDU>
Subject: pthreads eats mmap, select, fstreams?
To: proven@MIT.EDU
Message-Id: <01I2C2A87O8I99ZV32@CENTER.COLGATE.EDU>
X-Vms-To: IN%"proven@mit.edu"
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
Content-Transfer-Encoding: 7BIT

Here are some test cases for you. I am using gcc 2.7.2, linux 1.3.59, 
libc.so.5.2.18, and the libpthread.so that came with 5.2.18. 

select: this program works fine if I compile it normally, but segfaults if
I link it with libpthread.so. If I replace FD_SETSIZE with 1 as the first
argument of select, it no longer segfaults - but then the program's behavior 
is incorrect (with or without libpthread).

#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>

int main (void)
{
   fd_set active_set, read_set;
   FD_ZERO (&active_set);
   FD_SET (1, &active_set);
   read_set = active_set;
   if (select (FD_SETSIZE, &read_set, NULL, NULL, NULL) < 0)
     {
        perror ("select");
        exit (-1);
     }
   printf ("I am come as time, waster of nations.\n");
}

mmap: this works fine (assuming some sufficiently large file `somefile') until
I link it with libpthread, when mmap fails with `invalid argument'. I have
worked around it by doing all my mmapping before I load libpthread (I'm doing a
lot of dynamic loading anyways), but this contravenes one of my paramount
design principles and I would very much like to do all my mmapping at some
later point, from inside a thread, etc.

#include <sys/types.h>
#include <sys/mman.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>

int main (void)
{
   int fd;
   char *buff;
   fd = open ("somefile", O_RDWR);
   if (fd == -1)
     {
        perror ("open");
        exit (-1);
     }
   buff = mmap (NULL, getpagesize (), PROT_WRITE | PROT_READ,
                MAP_FILE | MAP_SHARED, fd, 0);
   if (errno)
     {
        perror ("mmap");
        exit (-1);
     }
   strcpy (buff, "Bringer of the hour that hastens to their doom.");
   munmap (buff, getpagesize ());
}

I also had some obscure troubles with sockets, which will take a while to
regenerate from old versions of the program; when I get a test case, I'll send
it you. Essentially what I was doing was making iostreams out of sockets and
using them pretty liberally; the most common error message was `bad file
number', but I got a few others interspersed. Perhaps this relates to the
failure of the test `test_stdio_1' with the error `file table leak'...?

Anyways, I have been very happy with pthreads despite these frustrations.
You've done a lovely job. It's like the evening news: good news is no news ;).

James




