Chinaunix首页 | 论坛 | 博客
  • 博客访问: 202903
  • 博文数量: 96
  • 博客积分: 1781
  • 博客等级: 上尉
  • 技术积分: 970
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-07 12:31
文章分类

全部博文(96)

文章存档

2014年(1)

2013年(14)

2012年(44)

2011年(37)

分类: LINUX

2013-04-19 14:42:45

  when we use pthread_create,some times we want to transe arg,linux make that we only can transe point to pthread_fun,
so we must make sure when we make pthread,and before new pthread get the argv point,wo must make sure that
then *argv is still live.
    so if we do not need to change the argv,we would better use local_val to get the value from point_argv.
    example
  fun_make(int number)
{
    for(i=0;i     {
        pthread_make(&pid_tcp_ser,NULL,tcp_ser,?);
    }
}
  we can use two method to achieve it.
  method 1:
            int id_number[number];
           for(i=0;i            {  
               id_number[i]=i;
               pthread_make(&pid_tcp_ser,NULL,tcp_ser,id_number+i); 
            }
           usleep(100);-->if no this ,the lase id_number is not correct in tcp_ser
  tcp_ser
         int i;
         i=*((int *)argv);
  method 2:
    
           for(i=0;i            {  
               pthread_make(&pid_tcp_ser,NULL,tcp_ser,i); --->just use i value be addres.
            }
  tcp_ser
         int i;
         i=(int )argv;--->cov argv value to be int number.
  in method 1: we transe the real addr,so we must make sure after tcp_ser get the the value then close the arg;
  int method 2:we use addr number to be number,this is a skill,but this is hard to undstand for others to undstand.
        
            
阅读(374) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~