bus error on pthread_join on IRIX 6.5

bus error on pthread_join on IRIX 6.5

Post by Tina L » Sun, 22 Jun 2003 03:21:44



Hello,

I'm writing a multi-threaded program using pthread on an IRIX 6.5 machine.
All is fine until it can't even pass the first pthread_join() and crashes
with bus error. I'm testing with this simple program (from
http://www.llnl.gov/computing/tutorials/workshops/workshop/pthreads/s...
join1.c), and it crashes and dies all the same (right on the "rc =
pthread_join(thread[t], (void **)&status);" statement). Unfortunately gdb is
ill-configured on the machine I'm working on. Would anyone have any idea how
I can find out why it's not working?

This program works fine on Linux and Solaris alike.

Many thanks.

Tina

#include <pthread.h>
#include <stdio.h>
#define NUM_THREADS     3

void *BusyWork(void *null)
{
   int i;
   double result=0.0;
   for (i=0; i<1000000; i++)
   {
     result = result + (double)random();
   }
   printf("Thread result = %e\n",result);
   pthread_exit((void *) 0);

Quote:}

int main(int argc, char *argv[])
{
   pthread_t thread[NUM_THREADS];
   pthread_attr_t attr;
   int rc, t, status;

   /* Initialize and set thread detached attribute */
   pthread_attr_init(&attr);
   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);

   for(t=0;t<NUM_THREADS;t++)
   {
      printf("Creating thread %d\n", t);
      rc = pthread_create(&thread[t], &attr, BusyWork, NULL);
      if (rc)
      {
         printf("ERROR; return code from pthread_create() is %d\n", rc);
         exit(-1);
      }
   }

   /* Free attribute and wait for the other threads */
   pthread_attr_destroy(&attr);
   for(t=0;t<NUM_THREADS;t++)
   {
      // *********BUS ERROR HERE************ //
      rc = pthread_join(thread[t], (void **)&status);
      if (rc)
      {
         printf("ERROR return code from pthread_join() is %d\n", rc);
         exit(-1);
      }
      printf("Completed join with thread %d status= %d\n",t, status);
   }

   pthread_exit(NULL);

Quote:}

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
 
 
 

bus error on pthread_join on IRIX 6.5

Post by Eric Sosma » Sun, 22 Jun 2003 04:33:44



> I'm writing a multi-threaded program using pthread on an IRIX 6.5 machine.
> All is fine until it can't even pass the first pthread_join() and crashes
> with bus error. [...]

>    int rc, t, status;
> [...]
>       // *********BUS ERROR HERE************ //
>       rc = pthread_join(thread[t], (void **)&status);

    This may or may not be the cause of your problem, but it
is certainly incorrect.  `status' is an `int', but pthread_join()
tries to store a `void*' there.  It may be that on the machine
in question `void*' is wider than an `int' or has stricter
alignment requirements -- either way, the results are likely
to be unpleasant.

    "If you lie to the compiler, it will get its revenge."
You've lied by telling the compiler it's safe to store a
`void*' value in `status', which isn't a `void*' at all.
Revenge has been visited upon you.  To atone, make `status'
a `void*' (and make adjustments in the subsequent printf()
call, too).

--


 
 
 

bus error on pthread_join on IRIX 6.5

Post by Tina L » Wed, 25 Jun 2003 05:52:38


Thanks! It's exactly the problem...

Tina


| >
| > I'm writing a multi-threaded program using pthread on an IRIX 6.5
machine.
| > All is fine until it can't even pass the first pthread_join() and
crashes
| > with bus error. [...]
| >
| >    int rc, t, status;
| > [...]
| >       // *********BUS ERROR HERE************ //
| >       rc = pthread_join(thread[t], (void **)&status);
|
|     This may or may not be the cause of your problem, but it
| is certainly incorrect.  `status' is an `int', but pthread_join()
| tries to store a `void*' there.  It may be that on the machine
| in question `void*' is wider than an `int' or has stricter
| alignment requirements -- either way, the results are likely
| to be unpleasant.
|
|     "If you lie to the compiler, it will get its revenge."
| You've lied by telling the compiler it's safe to store a
| `void*' value in `status', which isn't a `void*' at all.
| Revenge has been visited upon you.  To atone, make `status'
| a `void*' (and make adjustments in the subsequent printf()
| call, too).
|
| --

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----