摘要:shm_com.h: consumer: producer:
阅读全文
摘要:#include<stdio.h> #include<stdlib.h> #include<string.h> #include<fcntl.h> #include<unistd.h> #include<sys/wait.h> #include<sys/types.h> #include<sys/s
阅读全文
摘要:#include #include #include #include #include #include #define CUSTOMER_NUM 10 pthread_mutex_t mutex_x= PTHREAD_MUTEX_INITIALIZER; sem_t sem; int sem_val = 0; int iRet; void * get_service(void...
阅读全文
摘要:条件变量的激发与等待 pthread_cond_signal激活一个等待该条件的线程,taxi_001到了站台一看没人(没有等待该条件的线程),触发的条件变量被直接复位,于是taxi_001排在等待队列里面。
阅读全文
摘要:等待条件有两种方式:条件等待pthread_cond_wait()和计时等待pthread_cond_timedwait(),其中计时等待方式如果在给定时刻前条件没有满足,则返回ETIMEDOUT,结束等待,其中abstime以与time()系统调用相同意义的绝对时间形式出现,0表示格林尼治时间19
阅读全文
摘要:分离已创建线程: 分离线程: CMakeLists.txt 参考http://blog.csdn.net/dengshuai_super/article/details/52038970
阅读全文
摘要:除封包和解包,还使用#pragma控制struct内存对齐,适应不同的机器,保证服务器和客户端都能在对应位置上取到对应的值。 服务器: 客户端: 头文件:
阅读全文
摘要:刚给linux扩容,不用再担心 开发机的磁盘空间了 服务器: 客户端:
阅读全文
摘要:内核缓存控制,读写缓存阻塞大小。默认8K。 通过10k内核缓存控制,观察读写缓存变化。还有 内核缓存设置的时机,需要在listen之前,这是基于tcp的三次握手syn同步确认内核缓存大小。 服务器端: 客户端:
阅读全文
摘要:客户端: #include<stdio.h>#include<stdlib.h>#include<string.h>#include<errno.h>#include<sys/types.h>#include<sys/socket.h>#include<netinet/in.h>#include<a
阅读全文
摘要:借鉴网络文章,加了自己写的部分,重要的是理解多路IO复用。测试如下:
阅读全文
摘要:忽略SIGCHLD信号,交给内核处理子进程,避免产生僵尸进程。 服务器端: 客户端:
阅读全文