-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex03.c
61 lines (52 loc) · 1.05 KB
/
ex03.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
55
56
57
58
59
60
61
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include "../ex03/ft_strjoin.c"
char *ft_strjoin(int size, char **strs, char *sep);
int func_done = 0;
int timer_done = 0;
void *timer(void *var)
{
var = 0x00;
sleep(10);
timer_done = 1;
return (0);
}
void *execute(void *var)
{
var = 0x00;
char *strings[5] = {"AbuDhabi","42","Amazing","Piscine","Coding!!!"};
char *seperator = "-";
char *str;
int size = 5;
int i = 0;
printf("size = %d | sep = %s | strings = ",size,seperator);
for (i=0;i<size;i++)
printf("\"%s\" ",strings[i]);
str = ft_strjoin(size, strings, seperator);
printf("\nReturn = %s",str);
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);
}