Guys need help
#include<iostream>
#include<pthread.h>
#include<sys/types.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
void *Division(void *arg_div)
{
int *input =(int *)arg_div;
int result = input[0]/input[1];
cout<<"Final result"<<endl;
cout << result ;
pthread_exit(NULL);
}
void *Multiplication(void *arg_mul)
{
int *input =(int *)arg_mul;
int arg1[2];
arg1[0]=input[0]*input[1];
arg1[1]=input[2];
cout<<"Multiplication result"<<endl;
cout<<arg1[0];
cout<<arg1[1];
pthread_t div;
pthread_create(&div,NULL,Division,(void*)arg1);
pthread_join(div,NULL);
pthread_exit(NULL);
}
void *Addition(void *arg_add)
{
int *input =(int *)arg_add;
int arg[3];
arg[0]=input[0]+input[1];
arg[1]=input[2]+input[3];
arg[2]=input[4];
cout<<"output of add function"<<endl;
cout<<arg[0]<<endl;
cout<<arg[1]<<endl;
cout<<arg[2]<<endl;
pthread_t ad;
pthread_create(&ad,NULL,Multiplication,(void*)arg);
pthread_join(ad,NULL);
pthread_exit(NULL);
}
int main()
{
int values[5];
for(int i=0;i<5;i++)
{
cin >> values;
}
pthread_t pa;
pthread_create(&pa,NULL,Addition,(void*)values);
pthread_join(pa,NULL);
return 0;
}
(Threads Parameters Passing)
Using the same method as above create a program that passes parameters from one function to other. You must have at least four functions. Like if you implement a quartic equation function it includes operations such as square root, multiplication, subtraction and division. You must implement an equation something like that and create threads while passing parameters as void pointers to the next function.
(Thread Synchronization)
You will implement same equation. This time all threads are to be created in a main thread and you have to perform synchronization among these so that flow of the program remains same. You can use any method as you like signal handling, lock and test, semaphores or monitors. Use any method that you wish to implement.
Any one that can help mein this please