Linux MIPS Architecture development
 help / color / mirror / Atom feed
* Bug in pthread glibc 7.0 & 7.1
@ 2001-10-01 23:52 TWEDE,ROGER (HP-Boise,ex1)
  2001-10-02  0:10 ` H . J . Lu
  0 siblings, 1 reply; 4+ messages in thread
From: TWEDE,ROGER (HP-Boise,ex1) @ 2001-10-01 23:52 UTC (permalink / raw)
  To: 'linux-mips@oss.sgi.com'



The following code reveals a bug in the MIPS Gnu C Libraries available via
ftp on oss.sgi.com (ftp.linux.sgi.com).

The bug is posix thread related and occurs when using the libc and
libpthread versions available at:
/pub/linux/mips/redhat/7.1/RPMS/mipsel/glibc*

The bug also appears to exist in:
/pub/linux/mips/mipsel-linux/RedHat-7.0/RPMS/mipsel/glibc*

The bug does not exist in earlier versions of the pthread library, or on the
non-MIPS (non-SGI) distributions.  (ie. RedHat 7.0 for ix86 does not exhibit
a failure with this code, but RedHat 7.0/7.1 on mips does)

Upon failure the following code sequence will core dump (SEGV) instead of
exiting normally.


Thanks,

Roger Twede
Engineer/Scientist
Hewlett Packard Company


// CODE STARTS BELOW


#include <assert.h>
#include <pthread.h>
#include <sched.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>


struct ThreadStartInfo {
    pthread_mutex_t InitCompleteMutex;
    pthread_cond_t InitCompleteCond;
    void * (*Func)(void *);
    void * Arg;
    int Priority;
    char * ThreadName;
    unsigned char InitCompleteCount;
};


static void * StartFunction(void * Arg)
{

   struct ThreadStartInfo * StartInfo = (struct ThreadStartInfo *) Arg;
   int result;
   void * retVal = 0;

   assert(Arg != NULL);

   result = pthread_mutex_lock(&(StartInfo->InitCompleteMutex));
   assert(result == 0);
   printf("pid=%d thread mutex locked at x%x\n", getpid(),
&(StartInfo->InitCompleteMutex));
   StartInfo->InitCompleteCount = 1;
   result = pthread_cond_signal(&(StartInfo->InitCompleteCond));
   assert(result == 0);
   printf("pid=%d thread cond signal sent, unlocking at 0x%x\n", getpid(),
&(StartInfo->InitCompleteMutex));
   result = pthread_mutex_unlock(&(StartInfo->InitCompleteMutex));
   assert(result == 0);
   printf("pid=%d thread unlocked\n", getpid());
   sched_yield();
   printf("pid=%d yielded and back again\n", getpid());

   return(retVal);


}




int main(void)
{
    pthread_t ThreadObject;
    struct ThreadStartInfo StartInfo;
    pthread_mutexattr_t mutexAttr;
    pthread_attr_t threadAttr;
    pthread_condattr_t condAttr;
    int result = 0;

    StartInfo.ThreadName = "mythread";

    result = pthread_mutexattr_init(&mutexAttr);
    assert(result == 0);
    printf("pid=%d Init mutex\n", getpid());
    result = pthread_mutex_init(&(StartInfo.InitCompleteMutex), &mutexAttr);
    assert(result == 0);

    result = pthread_condattr_init(&condAttr);
    assert(result == 0);
    result = pthread_cond_init(&(StartInfo.InitCompleteCond), &condAttr);
    assert(result == 0);

    StartInfo.InitCompleteCount = 0;

    pthread_mutex_lock(&(StartInfo.InitCompleteMutex));

    printf("pid=%d About to create thread: %s\n", getpid(),
StartInfo.ThreadName);
    result = pthread_attr_init(&threadAttr);
    assert(result == 0);
    result = pthread_create(&ThreadObject,
                              &threadAttr,
                              &StartFunction,
                              (void *)&StartInfo);
    assert(result == 0);
    while ((result == 0) && (StartInfo.InitCompleteCount == 0))
    {
        do
        {
	   printf("pid=%d about to cond_wait for %s init 1.\n", getpid(),
StartInfo.ThreadName);
    	   result = pthread_cond_wait(&(StartInfo.InitCompleteCond),
&(StartInfo.InitCompleteMutex));
    	   printf("pid=%d back from cond_wait for %s init 1.  result=%d\n",
getpid(), StartInfo.ThreadName, result);
        } while (result == EINTR);
    }

    result = pthread_mutex_unlock(&(StartInfo.InitCompleteMutex));
    assert(result == 0);

    getchar();
    return 0;
}


// CODE ABOVE

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-10-02 16:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-10-01 23:52 Bug in pthread glibc 7.0 & 7.1 TWEDE,ROGER (HP-Boise,ex1)
2001-10-02  0:10 ` H . J . Lu
2001-10-02 12:09   ` Robin Humble
2001-10-02 16:14     ` H . J . Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox