OK, I'm feeling really dumb right now on a C program I'm working on. I'm getting a segfault that I assume is due to an int array I am creating. I say "i assume" because when I comment out that line of code, the segfaults go away.
The code is multi-threaded using pthreads, and I change the number of threads by a #define directive. A low number of threads never causes the segfault. I am manually assigning the stack size before creating the threads, and I am including the overhead of the array.
I've narrowed down the potential area where it occurs and I've gone through and commented out ALL array indexing operations to get eliminate the possibility of bad indexing. It's to the point where I am literally just indexing through for loops.
here's how I am allocating the thread stack size:
all of the threads are successfully created before the segfault, and if I run out of memory, the program catches it and aborts.Code:pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_getstacksize (&attr, &s); s = 7 * sizeof(int) + 1 * sizeof(long) + #ifndef SKIPSTEAL sizeof(int[NUM_THREADS - 1]) + #endif sizeof(struct1 *) + sizeof(struct2 *) + 100; if (s < PTHREAD_STACK_MIN) s = PTHREAD_STACK_MIN; pthread_attr_setstacksize (&attr, s);
I can't get the same place to show up in GDB for the segfault.
WTF am I missing here?