Question: #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

#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. Locations for written code is provided. Feel free to copy/paste the code into an IDE to ensure functionality
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
