Subj : trying to learn pthreads To : comp.programming.threads From : Beau Elliott Date : Fri Mar 18 2005 10:20 am I am trying to learn how to use pthreads. I am trying to use a struct to get around only having one variable. All I want to do is to use the thread I create to read in a value, and then print the result in the function that created the thread. The below code was compiled using the command: g++ thread.cpp -o thread -lpthread When I run the program, it prompts for the value to be read in, however I get a segmentation fault afterwards...can anyone tell me why? --- #include #include struct tdata{ int level; int left[2]; int right[2]; }; void *test(void *data){ tdata *temp; temp = (struct tdata *)data; //printf("%d", temp->level); printf("Please type in an integer: "); scanf("%d", temp->level); pthread_exit(0); } int main(int argc, char *argv[]){ struct tdata data; data.level = 0; data.whichside = 1; pthread_t id; pthread_create(&id, NULL, test, (void *) &data); pthread_join(id, NULL); printf("%d", data.level); return 0; } Thank you for your help! Cephus .