-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex00.c
54 lines (48 loc) · 1.16 KB
/
ex00.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include "../ex00/ft_iterative_factorial.c"
int ft_iterative_factorial(int nb);
int func_done = 0;
int timer_done = 0;
void *timer(void *var)
{
var = 0x00;
sleep(5);
timer_done = 1;
return (0);
}
void *execute(void *var)
{
var = 0x00;
printf("\n... You learn more from failure than from success ...\n\n");
printf("Calling ft_recursive_factorial(int nb);\n");
printf("nb = -1 | ret = %d | Expected = 0\n",ft_iterative_factorial(-1));
printf("nb = 0 | ret = %d | Expected = 1\n",ft_iterative_factorial(0));
printf("nb = 10 | ret = %d | Expected = 3628800\n",ft_iterative_factorial(10));
printf("nb = 20 | ret = %d | Expected = -288522240\n\n",ft_iterative_factorial(17));
func_done = 1;
return (0);
}
int main(void)
{
pthread_t threadId;
pthread_t timerId;
int threadId_Sig;
threadId_Sig = pthread_create(&threadId, NULL, execute, NULL);
pthread_create(&timerId, NULL, timer, NULL);
while (1) {
if (timer_done) {
pthread_cancel(threadId);
printf("*** TIMEOUT ***\n");
return (1);
}
if (func_done)
{
pthread_cancel(timerId);
return (0);
}
}
return (0);
}