源程序:
#include <unistd.h>
#include <pthread.h>
#include <stdio.h>
void *thread(void *str)
{
int i;
for(i=0;i<3;i++)
{
sleep(2);
printf("This in the thread:%d \n",i);
}
return NULL;
}
int main()
{
pthread_t pth;
int i;
/*创建线程并执行线程执行程序*/
int ret=pthread_create(&pth,NULL,thread,NULL);//第二个参数,属性通常为NULL
printf("the main process will be to run,but will be blocked soon \n");
/*阻塞,等待线程退出*/
pthread_join(pth,NULL);
printf("thread was exit \n");
for(i=0;i<3;i++)
{
sleep(1);
printf("thie in the main process: %d \n",i);
}
return 0;
}