'Bus error on OSX - pthreads

am trying to get my head around the following:

Have a small program am trying to port to OSX(intel) which calls function doWork() via pthread_create, in the function, I start by creating an array of long like such:

long myarray[DIMENSION]

on OSX, for the following values of DIMENSION, I get the following:

0->65434 = fine
65435->67037 = SIGBUS
67037+ = SIGSEGV

I'm totally confused here, I understand that SIGBUS is due to memory alignment issues usually, I checked sizeof(long) and it appears to be 8 on this platform. Can somebody point me in the right direction of docs I should be reading here?

Here is the source:


#include pthread.h
#include stdio.h
#define NUM_THREADS     5
#define DIMENSION       12345

void *doStuff(void *threadid)
{
   long array[DIMENSION];
   pthread_exit(NULL);
}

int main (int argc, char *argv[])
{
   pthread_t threads[NUM_THREADS];
   int rc;
   long t;
   for(t=0; t lt NUM_THREADS; t++){
      printf("In main: creating thread %ld\n", t);
      rc = pthread_create(&threads[t], NULL, doStuff, (void *)t);
      if (rc){
         printf("ERROR; return code from pthread_create() is %d\n", rc);
         exit(-1);
      }
   }
   pthread_exit(NULL);
}



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source