Hello,
this is a simple model for a simple program that will spawn a thread to run a given option in a menu (only option 1 and 2 run threads). The loop will need to wait for a thread to complete, so it uses the thread_join function
pthread_t newthread;
while ( 1 ) {
scanf ("%d", &option );
switch ( option ) {
case 1:
pthread_create ( newthread, NULL, function (1), NULL );
break;
case 2:
pthread_create ( newthread, NULL, function (2), NULL );
break;
case 3:
printf("message");
break;
case 4:
exit (0);
break;
}
thread_join ( newthread, NULL );
}
Well the thing is, the code will get there from option 3 also, so I wanted to know if this can cause problems (since option 3 doesn't create the thread).
Thanks for your time and help.