This is the mail archive of the libc-alpha@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[Robert Sim <simra@cim.mcgill.ca>] libc/1706: libpthread, multiprocessor linux and fgets/getline



Hi libc developers,

can somebody with an SMP system check this, please?

Thanks,
Andreas



Topics:
   libc/1706: libpthread, multiprocessor linux and fgets/getline


----------------------------------------------------------------------

Date: Sat, 22 Apr 2000 16:27:37 -0400
From: Robert Sim <simra@cim.mcgill.ca>
To: bugs@gnu.org
Subject: libc/1706: libpthread, multiprocessor linux and fgets/getline
Message-Id: <200004222027.QAA04724@Chess.McRCIM.McGill.EDU>


>Number:         1706
>Category:       libc
>Synopsis:       fgets and getline return success without writing to buffer
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    libc-gnats
>State:          open
>Class:          sw-bug
>Submitter-Id:   unknown
>Arrival-Date:   Sat Apr 22 16:30:01 EDT 2000
>Last-Modified:
>Originator:     
>Organization:
  -------------------------------------
  Robert Sim simra@cim.mcgill.ca
  http://www.cim.mcgill.ca/~simra
  So long, and thanks for all the Phish
>
>Release:        libc-2.1.3
>Environment:
Dual Pentium III 550MHZ Redhat 6.2 machine
	
Host type: i386-redhat-linux-gnu
System: Linux Chess.McRCIM.McGill.EDU 2.2.14-5.0smp #1 SMP Tue Mar 7 21:01:40 EST 2000 i686 unknown
Architecture: i686

Addons: c_stubs crypt glibc-compat linuxthreads
Build CFLAGS: -g -O3
Build CC: egcs
Compiler version: egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
Kernel headers: 2.2.14-5.0smp
Symbol versioning: yes
Build static: yes
Build shared: yes
Build pic-default: no
Build profile: yes
Build omitfp: no
Build bounded: no
Build static-nss: no
Stdio: libio

>Description:

Compile the program supplied below as per the comment line and execute on a
multi-processor machine.  It will eventually abort on the abort() instruction
because fgets failed to read the expected bytes into the buffer (in spite of
returning a success).  The program executes fine on a single-processor
machine, and also works fine if I replace fopen and fgets with the equivalent
open(2) and read(2) calls.  I have also observed this behaviour using the gnu
getline extension.

>How-To-Repeat:
/************************************************************************
gcc -Wall -o threadtest -D_REENTRANT threadtest.c -lpthread									 
Usage: ./threadtest
 ***********************************************************************/

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>

#define maxthreads 4
void * runthread(void* args);

int 
main(int argc, char ** argv) {
  int t;
  pthread_t threads[maxthreads];
  
  t=0;
  for (t=0; t<maxthreads; t++) {
    fprintf(stderr,"Spawning thread %d\n", t);
    pthread_create(&threads[t], NULL, 
		   runthread, argv[0]);
  }
  sleep(10000);
  exit(0);
}

void * runthread(void* args) {
  char buffer[1024];
  while (1) {
    FILE* fp=fopen("threadtest.c","r");
    if (!fp) {
      perror((char*)args);
      exit(1);
    }
    if (!fgets(buffer, 1023, fp)) {
      perror("Failed fgets");
      exit(1);
    }
    if (strncmp(buffer, "/*",2)) {
      fprintf(stderr, "Failed on *%s*\n",buffer);
      abort();
    } else fprintf(stderr,"%ld Success..\n",(long)fp);
    fclose(fp);
  }
  pthread_exit(0);
} 

>Fix:
Unknown.

>Audit-Trail:
>Unformatted:


------------------------------

End of forwardHdDsIm Digest
***************************



-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.rhein-neckar.de

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]