上一页 1 ··· 21 22 23 24 25 26 27 28 29 ··· 36 下一页

2021年5月8日

摘要: #include <iostream> #include <cstdio> #include <cstring> #include <cerrno> #include <unistd.h> #include <pthread.h> #include <arpa/inet.h> using names 阅读全文
posted @ 2021-05-08 17:28 lodger47 阅读(847) 评论(0) 推荐(0)
摘要: #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <sys/types.h> #include <arpa/inet.h> #include <string.h> #include <ctype.h> #inclu 阅读全文
posted @ 2021-05-08 16:30 lodger47 阅读(214) 评论(0) 推荐(0)
摘要: 只有整型和浮点型,才会存在大小端问题。大小端在使用上就好似鸡蛋要从那边吃,没有什么差异 小端模式对于英特尔的cpu来说就是小端在前大端在后(英特尔cpu是小端的) 国产cpu就是大端 使用16进制是为了直接申请内存,因为申请内存,是2的整数倍这样效率才好 8进制多用于权限相关 SOCKET 文件(内 阅读全文
posted @ 2021-05-08 11:45 lodger47 阅读(232) 评论(0) 推荐(0)

2021年5月7日

摘要: 生产者和消费者模型 信号量[加强版的互斥锁] int sem_init(setm_t *sem,int pshared,unsigned int valud); sem 定义的信号量,传出 pshared 0 代表线程信号量 非0 代表进程信号量 value 定义信号量的个数 摧毁信号量 int s 阅读全文
posted @ 2021-05-07 17:54 lodger47 阅读(438) 评论(0) 推荐(0)
摘要: 生产者和消费者模型 条件变量用来阻塞线程等待某个事件的发生,并且当等待的事件发生时,阻塞线程会被通知。 互斥锁一个明显的缺点是它只有两种状态:锁定和非锁定。而条件变量通过允许线程阻塞和等待另一个线程发送信号的方法弥补了互斥锁的不足,它常和互斥锁一起使用。 等待条件有两种方式:无条件等待pthread 阅读全文
posted @ 2021-05-07 15:51 lodger47 阅读(154) 评论(0) 推荐(0)
摘要: 读写锁 读写锁的特点: 读共享,写独占,写优先级高 读写锁仍然是一把锁,有不同的状态: 未加锁 读锁 写锁 读写锁的使用场景:适合读的线程多 常用 pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER; #include <pthread.h> / 阅读全文
posted @ 2021-05-07 15:23 lodger47 阅读(398) 评论(0) 推荐(0)
摘要: 互斥量 两个线程访问同一块共享资源,如果不协调顺序,容易造成数据混乱 加锁 mutex pthread_mutex_init 初始化 pthread_mutex_destory 摧毁 pthread_mutex_lock 加锁 pthread_mutex_unlock 解锁 互斥量的使用步骤 初始化 阅读全文
posted @ 2021-05-07 13:11 lodger47 阅读(235) 评论(0) 推荐(0)
摘要: #define __THR_CNT__ 5 //线程数 typedef struct CopyFileObj{ int num; char *copySrc; char *copyDst; int size; }CopyObj; void * thrFun(void *arg) { CopyObj 阅读全文
posted @ 2021-05-07 13:06 lodger47 阅读(284) 评论(0) 推荐(0)
摘要: int main(int argc,char *argv[]) { if(argc != 3) { printf("err: ./app filename\n"); return -1; } int fd_src = open(argv[1],O_RDWR); if(fd_src<0) { perr 阅读全文
posted @ 2021-05-07 11:25 lodger47 阅读(302) 评论(0) 推荐(0)
摘要: 1.获取系统时间函数 #include <ctime> using namespace std; int main( ) { // 基于当前系统的当前日期/时间 time_t now = time(0); // 把 now 转换为字符串形式 char* dt = ctime(&now); cout 阅读全文
posted @ 2021-05-07 01:15 lodger47 阅读(3637) 评论(0) 推荐(0)
上一页 1 ··· 21 22 23 24 25 26 27 28 29 ··· 36 下一页

导航