我没有得到任何输出,但我期待输出,因为下面的THREAD1 THREAD2是代码..
#include<iostream>
#include<pthread.h>
using namespace std;
void* fun(void *arg)
{
char *msg;
msg = (char*)arg;
cout<<msg<<endl;
}
int main()
{
pthread_t t1,t2;
t1 = pthread_create(&t1,NULL,fun,(void*)"THREAD1");
t2 = pthread_create(&t2,NULL,fun,(void*)"THREAD2");
pthread_join(t1,NULL);
pthread_join(t2,NULL);
// sleep (2);
return 0;
}
我将上面的代码更改为
pthread_create(&t1,NULL,fun,(void*)"THREAD1");
pthread_create(&t2,NULL,fun,(void*)"THREAD2");
现在我得到THREAD2 THREAD1但我需要THREAD1 THREAD2
现在我将代码更改为 >
pthread_create(&t1,NULL,fun,(void*)"THREAD1");
pthread_join(t1,NULL);
pthread_create(&t2,NULL,fun,(void*)"THREAD2");
pthread_join(t2,NULL);
现在我的结果是正确的THREAD1 THREAD2