-
-
Save AlessandroSpallina/756f9373ad38b88114af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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