69,336
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
void *mythread1(void *)
{
int i;
pthread_detach(pthread_self());
for(i=0;i<10;i++)
{
printf("this is the 1 pthread,created by zhouzheng!\n");
sleep(1);
}
pthread_exit(NULL);
}
void *mythread2(void *)
{
int i;
pthread_detach(pthread_self());
for(i=0;i<10;i++)
{
printf("this is the 2 pthread,created by zhouzheng!\n");
sleep(1);
}
pthread_exit(NULL);
}
int main()
{
int i=0;
int ret =0;
pthread_t id1,id2;
//ret = pthread_create(&id1,NULL,(void*)mythread1,NULL);
ret = pthread_create(&id1,NULL,mythread1,NULL);
if(ret) {
printf("Create pthread error!\n");
return 1;
}
//ret = pthread_create(&id2, NULL, (void*)mythread2,NULL);
ret = pthread_create(&id2, NULL, mythread2,NULL);
if(ret) {
printf("Create pthread error!\n");
return 1;
}
// pthread_join(id1,NULL);
// pthread_join(id2,NULL);
for(;;)
{
printf("this is main pthread\n");
sleep(1);
}
printf("Programme is end!\n");
return 0;
}