代码:
#include <iostream>
#include <pthread.h>
#include <unistd.h>
using namespace std;
void *threadRoutine(void *args)
{
while(true)
{
cout << "新线程:"<< (char*)args << " running ... " <<endl;
sleep(1);
int a =100;
a/=0;
}
}
int main()
{
pthread_t tid;
pthread_create(&tid,nullptr,threadRoutine,(void *)"thread 1");
while(true)
{
cout <<"main线程:" << " running ... " << endl;
sleep(1);
}
return 0;
}
运行结果: