int main(void) { pthread_t pid1, pid2; pthread_mutex_init(&mutex, NULL); printf("---------------------------\n"); printf("- START -\n"); printf("---------------------------\n"); load_msg_md5(); load_msg_ip(); // load_msg_url_w(); // load_msg_url_b(); ac_w.update(0); ac_b.update(1); load_msg_dns(); if(pthread_create(&pid1, NULL, func1, NULL)) { return -1; } if(pthread_create(&pid2, NULL, func2, NULL)) { return -1; } while(1) sleep(0); return 0; }
void * func1(void* args) { struct msgstru { int categary; char version[2048]; }; int imsgID; struct msgstru slQMsg,slRcvMsg; int ilrc; while(1) { //pthread_mutex_lock(&mutex); imsgID=msgget(MSGKEY, IPC_EXCL);//检查消息队列是否存在 if(imsgID < 0) { printf("消息队列不存在! errno=%d [%s]\n",errno,strerror(errno)); exit(-1); } ilrc = msgrcv(imsgID,&slRcvMsg,sizeof(struct msgstru),0,0);/*接收消息队列*/ if ( ilrc < 0 ) { printf("msgsnd()读消息队列失败,errno=%d[%s]\n",errno,strerror(errno)); exit(-1); } else { printf("消息队列read成功\n"); } //free(MSG_R); printf("TYPE = [%d]\n", slRcvMsg.categary); printf("VERSION = [%s]\n", slRcvMsg.version); // msgctl(imsgID,IPC_RMID,0); //删除消息队列 printf("---------------------------\n"); printf("- UPDATE \n"); printf("---------------------------\n"); switch(slRcvMsg.categary) { case 1: load_msg_ip(); break; case 2: // load_msg_url_w(); // load_msg_url_b(); ac_w.update(0); ac_b.update(1); break; case 3: load_msg_dns(); break; case 4: load_msg_md5(); break; default: printf("The categary type not 1 2 3 4\n"); } printf("---------------------------\n"); printf("- UPDATE END \n"); printf("---------------------------\n"); //pthread_mutex_unlock(&mutex); } }