Skip to content

Instantly share code, notes, and snippets.

@AlessandroSpallina
Created February 24, 2015 14:49
Show Gist options
  • Save AlessandroSpallina/756f9373ad38b88114af to your computer and use it in GitHub Desktop.
Save AlessandroSpallina/756f9373ad38b88114af to your computer and use it in GitHub Desktop.
/*
Author: Alessandro Spallina
Website: http://aleksnote.altervista.org
Email: [email protected]
* Creare un programma che
- Scrive a video "Ciao".
- Crea un thread che scrive a video "Bye", aspetta
2 secondi ed esce.
- Aspetta la chiusura del thread e mette a video la
scrittura "il thread ha finito" e il messaggio di
uscita del thread (a scelta dello studente).
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
//**********************************************************
void *function(){
printf("\nBye");
sleep(2);
pthread_exit("E' un triste giorno per la community dei thread");
}
//**********************************************************
int main(){
int result;
pthread_t attr;
void *uscita;
printf("Ciao");
result=pthread_create(&attr, NULL, function, NULL);
if(result==0){
pthread_join(attr, &uscita);
printf("\nil thread ha finito:\n%s\n", (char *)uscita);
exit(EXIT_SUCCESS);
}
else{
perror("\nERR: Impossibile Creare Thread");
exit(EXIT_FAILURE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment