forked from throwaway-root/DataStructers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThread-Fibanocci.c
43 lines (31 loc) · 1.01 KB
/
Thread-Fibanocci.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
//C Program to create a thread called fibanocci, which prints fibanocci series upto a given limit.
// Use 'cc -pthread Thread-Fibanocci.c' or 'gcc -pthread Thread-Fibanocci.c' to compile
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
int global[1];
void *printFibanocci(void *arg)
{
int *arr;
arr = arg;
int first = 0, second = 1, third;
int limit = arr[0];
printf("First Fibanocci Series Upto %d : \n",limit);
while (first < limit){
printf("%d ", first);
third = first + second;
first = second;
second = third;
}
return NULL;
}
int main()
{
printf("Enter The Limit : ");
scanf("%d",&global[0]);
pthread_t fibanocci; //unsigned integer value that stores the thread id of the thread created.
pthread_create(&fibanocci,NULL,printFibanocci,global); //thread creation
pthread_join(fibanocci,NULL);//waiting for the termination of a thread.
printf("\nThread ID: %lu ",fibanocci );//Printing thread ID
return 0;
}