#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
float rabbit;
float tortoise;
void *runner_rabbit(void *param);
void *runner_tortoise(void *param);
int main(int argc, char *argv[])
{
srand(time(NULL));
pthread_t tid_rabbit;
pthread_t tid_tortoise;
pthread_attr_t attr;
if (argc!=2) {
fprintf (stderr, "usage: a.out <integer value>\n");
return -1;
}
if (atoi(argv[1])<0) {
fprintf (stderr, "%d must be >=0\n", atoi(argv[1]));
return -1;
}
pthread_attr_init(&attr);
pthread_create(&tid_rabbit,&attr,runner_rabbit,argv[1]);
pthread_create(&tid_tortoise,&attr,runner_tortoise,argv[1]);
pthread_join(tid_rabbit,NULL);
pthread_join(tid_tortoise,NULL);
printf("%f %f\n",rabbit,tortoise);
}
void * runner_rabbit(void *param){
int hour=atoi(param);
rabbit=0;
for(int i=1;i<=hour;i++){
rabbit+=rand()%100;
}
}
void *runner_tortoise(void *param){
int hour=atoi(param);
tortoise=0;
for(int i=1;i<=hour;i++){
tortoise+=rand()%100;
}
}