I am trying to start a method from my main() as a new thread with pthread:
int main(int argc, char** argv) {
pthread_t shipGeneratorThread;
Port portMelbourne;
pthread_create(&shipGeneratorThread, NULL, portMelbourne.generateShips(), NULL);
return (EXIT_SUCCESS);
}
The Port class has a function that generates a ship:
void Port::generateShips() { //Generate 1 cargo ship every 2.5 hours bool stop = false;
while(!stop) {
if(numberOfShipsInBay < 20) {
Ship ship;
ship.setTicket(numberOfShipsInBay);
shipsWaitingToDock[numberOfShipsInBay] = ship;
term.displayMessage("A new ship has entered the port");
numberOfShipsInBay++;
} else {
term.displayMessage("A ship has been sent to another port");
}
usleep(FIVE_MINUTES * 30); //2.5 hours simulated time
}
}
But the compiler gives me an error, "invalid use of void expression" for the pthread create function.
I am new to C++ and threading, any ideas?