#include
#include
#include
pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
void threadone(void)
{
while(1)
{
printf("i am one!\n");
sleep(1); //延时1秒
}
}
void threadtwo()
{
while(1)
{
printf("i am two!\n");
sleep(1);
}
}
int main(void)
{
pthread_t id[2];
int i,ret1,ret2;
ret1=pthread_create(&id[0],NULL,(void *) threadone,NULL);//使id[*]和thread***相对应
ret2=pthread_create(&id[1],NULL,(void *) threadtwo,NULL);
pthread_mutex_init(&mut,NULL);
while(1)
{
if(ret1!=0)
{
printf ("lesson is error!\n");
exit(0);
}
if(ret2!=0)
{
printf ("lesson is error!\n");
exit(0);
}
if(id[0] !=0)
pthread_join(id[0],NULL);
if(id[1] !=0)
pthread_join(id[1],NULL);
}
return (0);
}
阅读(1078) | 评论(0) | 转发(0) |