forked from sudikrt/assignments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4_3_join.c
56 lines (48 loc) · 1.18 KB
/
4_3_join.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
#include <stdio.h>
#include <pthread.h>
struct pass_data
{
int count;
};
void* fib_cal (void* param)
{
struct pass_data* p = (struct pass_data*) param;
int i;
int f1 = 0, f2 = 1, fib = 0;
printf ("Fibonocci series :\n");
if (p->count == 1)
{
printf ("%d", f1);
}
else if (p->count == 2)
{
printf ("%d\t%d", f1, f2);
}
else
{
printf ("%d\t%d", f1, f2);
for (i = 3; i <= p->count; i++)
{
fib = f1 + f2;
printf ("%d\t", fib);
f1 = f2;
f2 = fib;
}
}
return NULL;
}
int main ()
{
pthread_t id1;
pthread_t id2;
struct pass_data arg1;
struct pass_data arg2;
arg1.count = 5;
arg2.count = 10;
pthread_create (&id1, NULL, &fib_cal, &arg1);
printf ("\n");
pthread_create (&id2, NULL, &fib_cal, &arg2);
pthread_join (id1, NULL);
pthread_join (id2, NULL);
return 0;
}