线程简单创建模板

#include <pthread.h>
#include <stdio.h>
#include <string.h>


void delay_ms(int  num)
{
  int i,j;
  for(i=0;i<num;i++)
  {
    for(j=0;j<9999;j++)
    {}
  }
}

void *snd_thread(void *arg)
{
	while(1)
	{
	  printf("in pthread_first  @.@   @.@ \n");
          delay_ms(8000);
	}
}

void *rec_thread(void *arg)
{
	while(1)
	{
	  printf("in pthread_second ~.~  ~.~ \n");
          delay_ms(8000);
	}
}

void *dis_thread(void *arg)
{
	while(1)
	{
	  printf("in pthread_third $.$  $.$ \n");
          delay_ms(8000);
	}
}
int main()
{

	//thread_init();//线程初始
	pthread_t pth_snd,pth_rec,pth_dis;  //标示符
	pthread_create(&pth_snd,NULL,snd_thread,NULL);
	pthread_create(&pth_rec,NULL,rec_thread,NULL);
	pthread_create(&pth_dis,NULL,dis_thread,NULL);


        delay_ms(1000);
	pthread_join(pth_snd,NULL);
	pthread_join(pth_rec,NULL);
	pthread_join(pth_dis,NULL);
        return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37967635/article/details/83351545
今日推荐