1

I'm doing parallel sorting using pthreads. Currently, I'm working with 4 threads and I have just started out , so right now no threads access same global locations. ( I have declared two variables globally, variables are arrays of large size and I'm making sure no two threads access the same index.)

Inside AASort , I have another function being called. This code works if I don't call any function within the AASort function.

unsigned  int Numbers [N/4] [4];
unsigned int vMergedArray[NumProcs][64][4];
unsigned int v[NumProcs][2][4];

main()
{
/* Initialize array of thread structures */
threads = (pthread_t *) malloc(sizeof(pthread_t) * NumProcs);
   assert(threads != NULL);

   for(threadId=0; threadId < NumProcs; threadId++) {

     ret = pthread_create(&threads[threadId], &attr, AASort, (void*) threadId);
     assert(ret == 0);

    }


     for(threadId=0; threadId < NumProcs; threadId++) {
      ret = pthread_join(threads[threadId], NULL);
      assert(ret == 0); 

}
}
Roopa
  • 11
  • 1
  • 1
    *This code works if I don't call any function within the AASort function.* implies the bug _might_ be in `AASort`. You should post it, too. Alternately, set the number of threads to one (1) and see if it still crashes. – ldav1s Dec 04 '13 at 19:33
  • Have you run it in a debugger or opened the core file after a crash to see exactly where it crashes? Also, you didn't even include the function where you claim your program is crashing, is that for some reason? – Macattack Dec 04 '13 at 19:34
  • It works now. There was a bug in the function. The index to array was going out of range. But, don't know why it was showing seg fault at pthreead_join though. Thanks Macattack for the reply. – Roopa Dec 05 '13 at 20:24

0 Answers0