[36] in Pthreads mailing list archive
Re: select problem
daemon@ATHENA.MIT.EDU (ts)
Fri Jul 7 15:11:12 1995
Date: Fri, 7 Jul 1995 18:24:46 +0200
From: ts <decoux@moulon.inra.fr>
To: nils@TechFak.Uni-Bielefeld.DE
Cc: pthreads@MIT.EDU
> I just tested the beta3 version of MIT pthreads hoping it works
> together with RPC. Unfortunately it does not.
>
> Getting a segmentation fault in the select code, I tested the
> test_select program in the test directory. It works fine as long as the
> number of filedescriptors to test in the select call is less than 42
> (this is no joke!). I tried 64 and got the following result using
> sunos4:
>
> threads forked: bg=0 fg=1a150
> initial thread 1a050 joining fg...
> select>
> Program received signal SIGSEGV, Segmentation fault.
> 0x106bc in select (numfds=64, readfds=0x33b58, writefds=0x0, exceptfds=0x0,
> timeout=0x0)
> at /homes/nils/tmp/pthreads.1_60_beta3/pthreads/select.c:131
> 131 if (fd_table[i]->fd.i >= data.nfds) {
> (gdb) where
> #0 0x106bc in select (numfds=64, readfds=0x33b58, writefds=0x0,
> exceptfds=0x0, timeout=0x0)
> at /homes/nils/tmp/pthreads.1_60_beta3/pthreads/select.c:131
> #1 0x23b0 in fg_routine (arg=0x0) at test_select.c:68
> #2 0xe440 in machdep_pthread_start () at machdep.c:90
> #3 0xf0005a34 in end ()
> (gdb) print i
> $1 = 42
>
>
> the reason is that fd_table[42] is NULL. This is the same problem
> that occurs when using the pmap_unset routine from the RPC lib.
>
> Unfortunately I could not figure out the root of the problem,
> so if anybody has a hint, I would be glad.
>
Problem is in `pthreads/fd.c' :
At initialisation, the number of possible descriptor is stored in dtablesize
|| void fd_init(void)
|| {
|| int i;
||
|| if ((dtablesize = machdep_sys_getdtablesize()) < 0) {
|| /* Can't figure out the table size. */
|| PANIC();
|| }
||
|| /* This is again temporary and can be bumped up if necessary. */
|| if (dtablesize > 1024) {
|| dtablesize = 1024;
|| }
||
|| if (fd_table = (struct fd_table_entry **)malloc(
|| sizeof(struct fd_table_entry) * dtablesize)) {
|| memset(fd_table, 0, sizeof(struct fd_table_entry) * dtablesize);
|| if (fd_check_entry(0) == OK) {
|| return;
|| }
|| }
||
|| /*
|| * There isn't enough memory to allocate a fd table at init time.
|| * This is a problem.
|| */
|| PANIC();
||
|| }
||
But when the descriptors are allocated, the variable `dtablecount' is used
|| static pthread_mutex_t fd_table_mutex = PTHREAD_MUTEX_INITIALIZER;
|| static const int dtablecount = 4096/sizeof(struct fd_table_entry);
|| int dtablesize;
||
|| /* ==========================================================================
|| * Allocate dtablecount entries at once and populate the fd_table.
|| *
|| * fd_init_entry()
|| */
|| int fd_init_entry(int entry)
|| {
|| struct fd_table_entry *fd_entry;
|| int i, round;
||
|| if (fd_table[entry] == NULL) {
|| round = entry - entry % dtablecount;
||
|| if ((fd_entry = (struct fd_table_entry *)malloc(
|| sizeof(struct fd_table_entry) * dtablecount)) == NULL) {
|| return(NOTOK);
|| }
||
|| for (i = 0; i < dtablecount; i++) {
|| fd_table[round + i] = &fd_entry[i];
||
|| fd_table[round + i]->ops = NULL;
In your case, you have :
dtablesize = 64
dtablecount = 42
all filehandle from 42 to 64 are not allocated and initialised
Guy Decoux