I am very new to QNX trying to do a small assignment for school.
I have some code (see below) - probably full of bad methodology
Basically I have two threads one updating values of variables periodically and one outputting variables periodically.
I need to create a timer to use instead of the for loop i used to give me actual seconds in reference to the CPU clock but I have no idea how to do this or where to start. Can someone point me in the right direction?
Here’s my code (please don’t laugh):
#include <pthread.h>
#include
#include
#include <stdio.h>
#include <stdlib.h>
#include <sys/neutrino.h>
#include <sched.h>
#include <unistd.h>
void *DAPsubroutine(void *);
void *DDsubroutine(void *);
#include <time.h>
#include <sys/siginfo.h>
double Ax = 1.0, Ay= -1.0, Az = 10.5,
g=10;
double X=0, Y=0, Z=0, Vx=0, Vy=0, Vz=0;
pthread_mutex_t mutex;
int main(){
std::cout<<“Navigation System\n”;
for (int T=0; T<21; T++){
pthread_create(NULL,NULL, &DAPsubroutine,(void *) T);
pthread_create(NULL,NULL, &DDsubroutine, (void *) T);
}
pause();
return EXIT_SUCCESS;
}
void DAPsubroutine(void c){
int t= (int) c;
if (t%1==0){
pthread_mutex_lock(&mutex);
Vx = Vx + Axt;
Vy = Vy + Ayt;
Vz = Vz + (Az-g)*t;
X = X + Vx*t;
Y = Y + Vy*t;
Z = Z + Vz*t;
pthread_mutex_unlock(&mutex);
}
}
void *DDsubroutine (void *c){
int t = (int) c;
if (t%5==0){
pthread_mutex_lock(&mutex);
std::cout << "For T = " << t << “seconds\n”;
std::cout << "Vx = " << Vx;
std::cout << "\nVy = " << Vy;
std::cout << "\nVz = " << Vz;
std::cout << "\nX = " << X;
std::cout << "\nY = " << Y;
std::cout << "\nZ = " << Y << “\n”;
pthread_mutex_unlock(&mutex);
}
}