Question: /** Complete the code that using threads and pipes. Location fro written code is provided. Fell free to copy/paste the code into an IDE to

/** Complete the code that using threads and pipes. Location fro written code is provided. Fell free to copy/paste the code into an IDE to ensure functionality.
*
* Threads and pipes
* The solution for this problem will create 2 threads. One to read in points,
* and a second to compute the distance between the points.
*/
#include
#include
#include
#include
#include
#define READ_END 0
#define WRITE_END 1
void *run_read(void *);
void *run_compute(void *);
int main(void) {
int fd[2]; /** Use this variable for the pipe */
/** Create the pipes and threads here */
return 0;
}
void *run_read(void *params) {
int x = 0, y = 0;
int fd[2];
/** All pipe manipulation must be done, but the printing reading of user input is provided */
for (int i = 1; i
printf("Enter point %d X value: ", i);
scanf("%d", &x);
write(fd[WRITE_END], &x, sizeof(x));
printf("Enter point %d Y value: ", i);
scanf("%d", &y);
write(fd[WRITE_END], &y, sizeof(y));
}
close(fd[WRITE_END]);
return NULL;
}
void *run_compute(void *params) {
int x[2], y[2];
int fd[2];
/** All pipe manipulation must be done, but the printing reading of user input is provided */
/** The output calculation is provided here */
double length = 0;
length = sqrt(pow(x[0]-x[1], 2) + pow(y[0]-y[1], 2));
printf("Distance between point (%d,%d) ", x[0], y[0]);
printf("and (%d,%d) is: %g ", x[1], y[1], length);
close(fd[READ_END]);
return NULL;
}
 /** Complete the code that using threads and pipes. Location fro
written code is provided. Fell free to copy/paste the code into an
IDE to ensure functionality. * * Threads and pipes * The solution
** Complete the code that using threads and pipes. Location fro written code is provided. Fell free to copy/paste the code into an IDE to ensure functionality. * Threads and pipes * The solution for this problem will create 2 threads. One to read in points, * and a second to compute the distance between the points. */ #include #include #include #include #include #define READ_END O #define WRITE_END 1 void *run_read(void *); void *run_compute(void *); int main(void) { int fd[2]; /** Use this variable for the pipe */ /** Create the pipes and threads here */ return 0; for (int i = 1; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!