I written this code:
#include <stdio.h>
#include <pthread.h>
void* cuoco(void* arg)
{
fprintf(stderr,"Inizio codice cuoco\n");
fprintf(stderr,"Fine codice cuoco\n");
return NULL;
}
void* cameriere(void* arg)
{
fprintf(stderr,"Inizio codice cameriere\n");
fprintf(stderr,"Fine codice cameriere\n");
return NULL;
}
void* cliente(void* arg)
{
fprintf(stderr,"Inizio codice cliente\n");
fprintf(stderr,"Fine codice cliente\n");
return NULL;
}
int main(int argc, char* argv[])
{
void* (*routine)(void*);
void* result;
routine=cuoco;
pthread_t thread_cuoco,thread_cameriere,thread_cliente;
pthread_create(&thread_cuoco,NULL,routine,*argv);
return 0;
}
Just to test how threads work.But the body of the function cuoco is never executed.This because it shall print “Inizio codice cuoco” and “fine codice cuoco” but it does not.
You need to use
pthread_join, so that yourmainfunction waits for the thread to execute before terminating the program.