Write a C program using Kthreads to add two numberSolutionAn
Write a C program using Kthreads to add two number:
Solution
Answer:
You can use k instead of p but I used p because it creates at user level and the other one works on kernal level but the functionality is same and p is recommended option :
int global[2];
void *sum_thread(void *arg)
{
int *args_array;
args_array = arg;
int n1,n2,sum;
n1=args_array[0];
n2=args_array[1];
sum = n1+n2;
printf(\"N1 + N2 = %d\ \",sum);
return NULL;
}
int main()
{
printf(\"First number: \");
scanf(\"%d\",&global[0]);
printf(\"Second number: \");
scanf(\"%d\",&global[1]);
pthread_t tid_sum;
pthread_create(&tid_sum,NULL,sum_thread,global);
pthread_join(tid_sum,NULL);
return 0;
}
