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) |