raac
March 25th, 2011, 10:50 PM
Ok guys I'm doing this program in C and I don't know why i'm getting segmentation fault.
I think all you need is this to get the idea... (I'm giving meaningless code, I just need help on the pointer manipulation which i think is the reason of the seg fault)
typedef struct ti{
int value1;
int value2;
}info;
//Main
info *solu;
pthread_t tid;
solu->value1 = 3;
solu->value2 =1;
if(error = pthread_create(&tid, NULL, queen_thread, (void *) solu))
fprintf(stderr, "Failed to create thread: %s\n", strerror(error));
if (error = pthread_join(tid, NULL)) {
fprintf(stderr, "Failed to join thread: %s\n", strerror(error));
exit(-1);
}
//queen_thread function
void *queen_thread(void *infopointer){
info solutions;
solutions = *(info *) infopointer;
solutions->value1 = 4;
return NULL;
}
/
I think all you need is this to get the idea... (I'm giving meaningless code, I just need help on the pointer manipulation which i think is the reason of the seg fault)
typedef struct ti{
int value1;
int value2;
}info;
//Main
info *solu;
pthread_t tid;
solu->value1 = 3;
solu->value2 =1;
if(error = pthread_create(&tid, NULL, queen_thread, (void *) solu))
fprintf(stderr, "Failed to create thread: %s\n", strerror(error));
if (error = pthread_join(tid, NULL)) {
fprintf(stderr, "Failed to join thread: %s\n", strerror(error));
exit(-1);
}
//queen_thread function
void *queen_thread(void *infopointer){
info solutions;
solutions = *(info *) infopointer;
solutions->value1 = 4;
return NULL;
}
/