I'm pretty sure there's just a small bug I'm missing, but I can't seem to find it.
Error:
g++ -Wall Proj3.cpp -o proj3 -pthread
Proj3.cpp: In function âvoid initLockVar()â:
Proj3.cpp:52: error: expected primary-expression before â{â token
Proj3.cpp:52: error: expected `;' before â{â token
Proj3.cpp:256: error: expected `}' at end of input
make: *** [Proj3] Error 1
Code up to that point. In this comment-removed code block, line 34 in the code block corresponds to line 52 in the error (original code.)
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <time.h>
#include <queue>
#include <iostream>
#include <fstream>
#include <signal.h>
using namespace std;
struct car {
time_t arrivalTime; // Arrival time of the car
time_t startTime; // Time car moves through the intersection
int id; // ID# of the car
char dir; // Which direction queue car is on
};
const int minToRun = 5; // Minutes to run the simulation
// Marker for when to end the simulation.
time_t endTime = time(NULL) + (60 * minToRun);
int numCars; // Used to keep track of total cars.
queue<car> nStreetQueue; // Queue of cars waiting on the north street.
queue<car> sStreetQueue; // Queue of cars waiting on the south street.
// Mutex locks and conditional variables
pthread_mutex_t lock;
pthread_cond_t nNotEmpty;
// Output streams
ofstream carLog("carevent.log");
ofstream flagLog("flagperson.log");
void initLockVar() {
lock = PTHREAD_MUTEX_INITIALIZER;
nNotEmpty = PTHREAD_COND_INITIALIZER;
srand(time(NULL));
carLog << "carID direction arrival-time start-time end-time"
<< endl;
flagLog << "Time State" << endl;
}
Any help would be greatly appreciated.