forked from iedcbootcampcec/letshack-basic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththread1.c
More file actions
35 lines (31 loc) · 645 Bytes
/
thread1.c
File metadata and controls
35 lines (31 loc) · 645 Bytes
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
//Implementation Of threads
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
int global[2];
void * sumof(void*arg)
{
int *arr;
arr=arg;
int n1,n2,sum;
n1=arr[0];
n2=arr[1];
printf("Sum of two integers, %d+%d=%d \n", n1,n2,(n1+n2));
return NULL;
}
// thread name- add
int main()
{
printf("Enter 1st Number: ");
scanf("%d", &global[0]);
printf("Enter 2nd Number: ");
scanf("%d", &global[1]);
pthread_t add;
pthread_create (&add,NULL, sumof,global);
pthread_join(add,NULL);
printf("Thread ID :%lu \n",add);
pthread_exit(NULL);
return 0;
}
// to complile- gcc filename.c -lpthread
// to run- ./a.out