使用std::thread时的illegal instruction错误
在使用多线程时,出现了illegal instruction错误,经仔细排查,发现错误的原因非常可笑,是因为线程函数没写返回值。
错误示例:
void * function(void *arg)
{
printf("function\n");
sleep(5);
//没有返回值
}
int main() {
std::cout << "Hello, World!" << std::endl;
std::thread thread1=std::thread(function, nullptr);
while(true) {
}
return 0;
}