#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
#include<unistd.h>
#include<stdint.h>
void* threadFunct(void *arg){
int sleeptime = (int)(intptr_t)arg;
printf("Hallo. Ich bin Thread %ld.\n",pthread_self());
fflush(stdout);
printf("Sleeptime: %d\n", sleeptime);
fflush(stdout);
sleep(sleeptime); //schlafe 2000000 us
pthread_exit(NULL);
}
int main(){
pthread_t thread[3];
for(int i = 0; i <= 2; i++){
printf("Thread erzeugt, warte auf Beendigung...\n");
pthread_create(&thread[i],NULL,&threadFunct,(void *)(intptr_t)(i+10));
}
for(int i = 0; i <= 2; i++){
pthread_join(thread[i],NULL);
}
printf("Thread beendet. Beende Prozess.\n");
return 0;
}