代码:
#include <iostream>
#include <pthread.h>
#include <unistd.h>
using namespace std;
void *threadRoutine(void *args)
{
int i=0;
while(true)
{
cout << "新线程:"<< (char*)args << " running ... " <<endl;
sleep(1);
if(i++ == 10)break;
}
cout << "new thread quit ..." << endl;
return (void *)10;
}
int main()
{
pthread_t tid;
pthread_create(&tid,nullptr,threadRoutine,(void *)"thread 1");
void *ret = nullptr;
pthread_join(tid,&ret);
cout << "main thread wait done...main quit ...: new thread quit : " << (long long)ret <<"\n";
return 0;
}
运行结果:![](https://i-blog.csdnimg.cn/blog_migrate/d8735e1aec17696542d969da7643c604.png)