上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 14 下一页
摘要: //account.h #ifndef _ACCOUNT_H #define _ACCOUNT_H #include <pthread.h> typedef struct{ int code; double balance; //定义一把互斥锁,用来对多线程操作的银行账户(共享资源)进行加锁(保护) 阅读全文
posted @ 2023-03-26 17:14 踏浪而来的人 阅读(24) 评论(0) 推荐(0) 编辑
摘要: CPU对变量的计算分为三个步骤: 1. 从内存读取变量到寄存器(如add寄存器) 2. 将读取到的变量进行计算 3. 将寄存器中计算的值写入内存 如有两个线程(线程1和线程2)对共享资源(全局变量)a=0进行自增操作(a++),可能出现如下情况: 线程1进行a++时,会将变量a读取寄存器,在对变量a 阅读全文
posted @ 2023-03-26 10:46 踏浪而来的人 阅读(75) 评论(0) 推荐(0) 编辑
摘要: 原型: int select(int max fdp1, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) 功能: 委托内核检查描述符集是否准备好(即可以使用,用于双方通信) 参数: fdp1 阅读全文
posted @ 2023-03-22 19:45 踏浪而来的人 阅读(108) 评论(0) 推荐(0) 编辑
摘要: fcnt_vector_fd.h #ifndef _FCNTL_VECTOR_FD_H #define _FCNTL_VECTOR_FD_H typedef struct{ int *fd; int conter; int max_conter; }VectorFd; extern VectorFd 阅读全文
posted @ 2023-03-21 23:24 踏浪而来的人 阅读(17) 评论(0) 推荐(0) 编辑
摘要: //udp_server.c#include <signal.h>#include <stdio.h>#include <errno.h>#include <unistd.h>#include <stdlib.h>#include <time.h>#include <string.h>#includ 阅读全文
posted @ 2023-03-20 19:35 踏浪而来的人 阅读(24) 评论(0) 推荐(0) 编辑
摘要: UDP客户端/服务器编程模型: 发送函数: 接受函数: 阅读全文
posted @ 2023-03-19 22:15 踏浪而来的人 阅读(7) 评论(0) 推荐(0) 编辑
摘要: tcp_server_mulpthread.c #include <signal.h> #include <stdio.h> #include <errno.h> #include <unistd.h> #include <stdlib.h> #include <time.h> #include < 阅读全文
posted @ 2023-03-19 22:05 踏浪而来的人 阅读(15) 评论(0) 推荐(0) 编辑
摘要: tcp_server_mulprocess.c #include <signal.h> #include <stdio.h> #include <errno.h> #include <unistd.h> #include <stdlib.h> #include <time.h> #include < 阅读全文
posted @ 2023-03-19 20:33 踏浪而来的人 阅读(19) 评论(0) 推荐(0) 编辑
摘要: 方式: 1. 多进程模型 2. 多线程模型 3. IO多路转换 1. 多进程模型: 父进程循环调用accept来接受客服端的连接,当有客户端连接上来时,就调用fork函数创建子进程来与客户端对接。 如果不创建子进程,那么父进程调用read函数就可能阻塞,就不能实现并发性的处理了。 2. 多线程模型: 阅读全文
posted @ 2023-03-19 10:51 踏浪而来的人 阅读(23) 评论(0) 推荐(0) 编辑
摘要: 三次握手: 四次挥手: 阅读全文
posted @ 2023-03-14 23:00 踏浪而来的人 阅读(14) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 14 下一页