Question: please fix the code based on the question. code in c linux ubuntu #include #include #include #include #include #include #define LOWER_TEMP_BOUND 0.00 #define UPPER_TEMP_BOUND 100.00

please fix the code based on the question. code in c linux ubuntu
#include
#include
#include
#include
#include
#include
#define LOWER_TEMP_BOUND 0.00
#define UPPER_TEMP_BOUND 100.00
#define LOWER_PRESSURE_BOUND 150.00
#define UPPER_PRESSURE_BOUND 300.00
void *temperature()
{
int temperature = (int)malloc(sizeof(int));
temperature = LOWER_TEMP_BOUND + (int)(UPPER_TEMP_BOUND*rand()/(RAND_MAX+1.0));
return (void*)temperature;
}
void *pressure()
{
int pressure = (int)malloc(sizeof(int));
pressure = LOWER_PRESSURE_BOUND + (int)(UPPER_PRESSURE_BOUND*rand()/(RAND_MAX+1.0));
return (void*)pressure;
}
void *display()
{
pthread_t t1, t2;
void *returntemperature, *returnpressure;
int *temperaturevalue, *pressurevalue;
int display = (int)malloc(sizeof(int));
pthread_create(&t1, NULL, temperature, &temperaturevalue);
pthread_create(&t2, NULL, pressure, &pressurevalue);
pthread_join(t1, &returntemperature);
pthread_join(t2, &returnpressure);
printf(" Writing The Temperature...");
temperaturevalue = (int *)returntemperature;
printf(" \t\tThe Temperature value is = %d C",*temperaturevalue);
printf(" Writing The Temperature...");
pressurevalue = (int *)returnpressure;
printf(" \t\tThe Pressure value is = %d Pa",*pressurevalue);
free(returntemperature);
free(returnpressure);
return (void *)display;
}
void main(void)
{
pthread_t t3;
void *returndisplay;
int *displayvalue;
while(1)
{
pthread_create(&t3, NULL, display, &displayvalue);
pthread_join(t3, &returndisplay);
printf("\tWait for 4 seconds... ");
printf("\tWait for next reading... ");
sleep(4);
free(returndisplay);
}
}
1. Ability to develop Periodic Real Time Threads using POSIX RT profile API This lab is a continuation from lab 4. Here you should address the same problem of having 2 threads that generates data (temperature and pressure), and another process which read both value generated by the other 2 process. The difference is, precise timing of all periodic thread must be imposed. Note, you must used POSIX RT profile API to acquire precise timing for this assignment a) The first thread should mimics acquiring a temperature value from the equation below: temperature LOWER_TEMP_BOUND +(int) (UPPER_TEMP_BOUND*rand() / (RAND_MAX+1.0)); and return the value to the calling main thread. b) The second thread should mimics acquiring a pressure value from the equation below: presure = LOWER PRESURE_BOUND +(int) (UPPER_PRESURE_BOUND* rand() / (RAND_MAX+1.0)); and return the value to the calling main thread. c) The third thread should receive both of this value and display them to the screen. d) The pressure and temperature value must be sampled at every 4 and 4 seconds respectively. e) The third thread period is also 4 seconds
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
