全部博文(214)
分类:
2007-11-27 16:46:15
|
在编译时要加上"-lpthread", 否则的话程序不能工作在多线程模式下.
gcc -o test -l pthread test.c
目标是由线程来将主程序中的数据加一, 结果完成我的要求.
wait 1 second! -- err=0, tid=4, val=11
wait 1 second! -- err=0, tid=6, val=12
wait 1 second! -- err=0, tid=7, val=13
chinaunix网友2008-01-21 19:56:39
#include"mihu.h" void *recv(void *arg) { int i = 0; int client_sock_fd = -1; char message[20] = ""; LJC *p1; LJC *p2; LJC *p; RECV_MSG recv_msg; client_sock_fd = *(int*)arg; p1 = (LJC *)malloc(sizeof(LJC)); p1->next = NULL; while(1) { memset(&recv_msg,0,sizeof(recv_msg)); if(recv(client_sock_fd,(char *)&recv_msg,sizeof(recv_msg),0) == -1) { printf("recv error~~~~~~~~~! \n"); break; } p2 = (LJC *