I've had three different lab TAs look at my code and none of them have been able to help me, so I've decided to try here. Unless I delete all code relating to both gettimeofday and any semaphores, I get a "Segmentation fault (core dumped)" error. I've boiled down my code to only the main thread with simple declarations to attempt to get to the root of the problem.
My code:
#include <pthread.h>
#include <semaphore.h>
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <sys/shm.h>
#include <sys/time.h>
void *threadN (void *); /* thread routines */
pthread_t tid[1]; /* array of thread IDs */
int main()
{
int i,j;
/* here create and initialize all semaphores */
int mutex = sem_create(777777, 1);
int MatrixA[6000][3000];
for (i=0; i < 6000; i++) {
for (j=0; j < 3000; j++) {
MatrixA[i][j]=i*j;
}
}
int MatrixB[3000][1000];
for (i=0; i < 3000; i++) {
for (j=0; j < 1000; j++) {
MatrixB[i][j]=i*j;
}
}
int MatrixC[6000][1000];
struct timeval tim;
gettimeofday(&tim, NULL);
float t1=tim.tv_sec+(tim.tv_usec/1000000.0);
gettimeofday(&tim, NULL);
float t2=tim.tv_sec+(tim.tv_usec/1000000.0);
printf("%.2lf seconds elapsed\n", t2-t1);
sem_rm(sem_open(777777, 1));
return 0;
}
I'm completely stumped here.