当前位置: 技术问答>linux和unix
一调用链表的next指针 就有问题
来源: 互联网 发布时间:2016-10-16
本文导语: struct pth_bl{ pthread_t id; int connect; struct cmdnode *cmd_first; struct cmdnode *cmd_end;//shengming struct sockaddr_in client_addr; int userid; int cmdnum; struct pth_bl* next; struct databag *bag_buf[BUFSZ]; sem_t bagseme,bagsemf; int bagfirst,baglast...
struct pth_bl{
pthread_t id;
int connect;
struct cmdnode *cmd_first;
struct cmdnode *cmd_end;//shengming
struct sockaddr_in client_addr;
int userid;
int cmdnum;
struct pth_bl* next;
struct databag *bag_buf[BUFSZ];
sem_t bagseme,bagsemf;
int bagfirst,baglast;
};
int init_pth(struct pth_bl *pb,struct sockaddr_in client_addr,int userid){
if((pb=(struct pth_bl *)malloc(sizeof(struct pth_bl)))==NULL){
perror("malloc");
return 0;
}
sem_init(&(pb->bagsemf),0,0);
sem_init(&(pb->bagseme),0,BUFSZ);
struct cmdnode *first=(struct cmdnode*)malloc(sizeof(struct cmdnode));
first->cmd=0;
first->cmdnumnode=0;
first->next=NULL;
pb->cmd_first=first;
pb->cmd_end=first;
pb->cmdnum=0;
pb->client_addr=client_addr;
pb->userid=userid;
pb->next=NULL;
pb->bagfirst=0;
pb->baglast=0;
sem_init(&(pb->bagsemf),0,BUFSZ);
sem_init(&(pb->bagseme),0,BUFSZ);
return 1;
}
int addpb(struct pth_bl *new2){
printf("addpbn");
//pthread_mutex_lock(&pbmutex);
printf("addpbn");
printf("addpbn");
//if(phead.first!=NULL)
new2->next=phead.first;
printf("addpbn");
phead.first=new2;printf("addpbn");
//pthread_mutex_unlock(&pbmutex);
printf("addpbn");
}
.. struct pth_bl *pt;
printf("perse:ban");
pthread_t id;
init_pth(pt,(*client_sockaddr),toint(buf,7,8));
printf("perse:ban");
printf("perse:ban");
tosend(bag);
if(phead.first==NULL)
printf("perse:addpbn");
if(pt->next==NULL)
printf("perse:addpbn");
或
addpb(pt);
..
调用addpb这段话指出两个addpb现在程序有三个进程 出错的进程现在就一个线程 现在一调用struct pth_bl的next就停止不动了 应该不是线程阻塞的问题 我就得是不是递归了
pthread_t id;
int connect;
struct cmdnode *cmd_first;
struct cmdnode *cmd_end;//shengming
struct sockaddr_in client_addr;
int userid;
int cmdnum;
struct pth_bl* next;
struct databag *bag_buf[BUFSZ];
sem_t bagseme,bagsemf;
int bagfirst,baglast;
};
int init_pth(struct pth_bl *pb,struct sockaddr_in client_addr,int userid){
if((pb=(struct pth_bl *)malloc(sizeof(struct pth_bl)))==NULL){
perror("malloc");
return 0;
}
sem_init(&(pb->bagsemf),0,0);
sem_init(&(pb->bagseme),0,BUFSZ);
struct cmdnode *first=(struct cmdnode*)malloc(sizeof(struct cmdnode));
first->cmd=0;
first->cmdnumnode=0;
first->next=NULL;
pb->cmd_first=first;
pb->cmd_end=first;
pb->cmdnum=0;
pb->client_addr=client_addr;
pb->userid=userid;
pb->next=NULL;
pb->bagfirst=0;
pb->baglast=0;
sem_init(&(pb->bagsemf),0,BUFSZ);
sem_init(&(pb->bagseme),0,BUFSZ);
return 1;
}
int addpb(struct pth_bl *new2){
printf("addpbn");
//pthread_mutex_lock(&pbmutex);
printf("addpbn");
printf("addpbn");
//if(phead.first!=NULL)
new2->next=phead.first;
printf("addpbn");
phead.first=new2;printf("addpbn");
//pthread_mutex_unlock(&pbmutex);
printf("addpbn");
}
.. struct pth_bl *pt;
printf("perse:ban");
pthread_t id;
init_pth(pt,(*client_sockaddr),toint(buf,7,8));
printf("perse:ban");
printf("perse:ban");
tosend(bag);
if(phead.first==NULL)
printf("perse:addpbn");
if(pt->next==NULL)
printf("perse:addpbn");
或
addpb(pt);
..
调用addpb这段话指出两个addpb现在程序有三个进程 出错的进程现在就一个线程 现在一调用struct pth_bl的next就停止不动了 应该不是线程阻塞的问题 我就得是不是递归了
|
if(pt->next==NULL)这句是肯定不会阻塞的,是假象.