【发布时间】:2015-02-18 09:09:48
【问题描述】:
我正在尝试从我的 main() 开始一个方法,作为一个带有 pthread 的新线程:
int main(int argc, char** argv) {
pthread_t shipGeneratorThread;
Port portMelbourne;
pthread_create(&shipGeneratorThread, NULL, portMelbourne.generateShips(), NULL);
return (EXIT_SUCCESS);
}
Port 类有一个生成船的函数:
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
}
}
但是编译器给了我一个错误,“无效使用无效表达式”用于 pthread 创建函数。
我是 C++ 和线程的新手,有什么想法吗?
【问题讨论】:
标签: c++ multithreading object pthreads