当前位置: 首页 > news >正文

7.19IO

思维导图

第一题:测试错误检查锁和递归锁是否会造成死锁状态

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
#include <semaphore.h>
#include <wait.h>
#include <signal.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <semaphore.h>
#include <sys/msg.h>
#include <sys/shm.h>
#include <sys/un.h>typedef struct sockaddr_in addr_in_t; 
typedef struct sockaddr addr_t;
typedef struct sockaddr_un addr_un_t;pthread_mutex_t m1;
pthread_mutex_t m2;void *run(void* arg)
{while(1){pthread_mutex_lock(&m1);printf("a\n");sleep(1);}
}int main(int argc, const char *argv[])
{pthread_t id;pthread_create(&id,0,run,0);pthread_detach(id);pthread_mutexattr_t attr;pthread_mutexattr_init(&attr);pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_ERRORCHECK_NP);pthread_mutex_init(&m1,&attr);pthread_mutex_init(&m2,&attr);while(1){pthread_mutex_lock(&m2);printf("A\n");sleep(1);}return 0;
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
#include <semaphore.h>
#include <wait.h>
#include <signal.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <semaphore.h>
#include <sys/msg.h>
#include <sys/shm.h>
#include <sys/un.h>typedef struct sockaddr_in addr_in_t; 
typedef struct sockaddr addr_t;
typedef struct sockaddr_un addr_un_t;pthread_mutex_t m1;
pthread_mutex_t m2;void *run(void* arg)
{while(1){pthread_mutex_lock(&m1);printf("a\n");sleep(1);}
}int main(int argc, const char *argv[])
{pthread_t id;pthread_create(&id,0,run,0);pthread_detach(id);pthread_mutexattr_t attr;pthread_mutexattr_init(&attr);pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE);pthread_mutex_init(&m1,&attr);pthread_mutex_init(&m2,&attr);while(1){pthread_mutex_lock(&m2);printf("A\n");sleep(1);}return 0;
}

http://www.lryc.cn/news/403573.html

相关文章:

  • 【Vue】深入了解 Axios 在 Vue 中的使用:从基本操作到高级用法的全面指南
  • 【Qt】窗口
  • 代码随想录训练营【贪心算法篇】
  • Spark中的JOIN机制
  • WebRTC QOS方法十三.1(TimestampExtrapolator接收时间预估)
  • 深入了解 GCC
  • vscode 打开远程bug vscode Failed to parse remote port from server output
  • 前端组件化技术实践:Vue自定义顶部导航栏组件的探索
  • PyTorch Autograd内部实现
  • 微信小程序 vant-weapp的 SwipeCell 滑动单元格 van-swipe-cell 滑动单元格不显示 和 样式问题 滑动后删除样式不显示
  • 3.4、matlab实现SGM/BM/SAD立体匹配算法计算视差图
  • 【瑞吉外卖 | day07】移动端菜品展示、购物车、下单
  • 前端Vue项目中腾讯地图SDK集成:经纬度与地址信息解析的实践
  • 鸿蒙开发StableDiffusion绘画应用
  • 华为OD机考题(HJ61 放苹果)
  • 浅谈Visual Studio 2022
  • spark 动态资源分配dynamicAllocation
  • 【C语言ffmpeg】打开第一个视频
  • 【Langchain大语言模型开发教程】模型、提示和解析
  • Flutter 中的基本数据类型:num、int 和 double
  • 基于Python+Django,开发的一个在线教育系统
  • 密码学原理精解【9】
  • 【Nacos】Nacos服务注册与发现 心跳检测机制源码解析
  • python 66 个冷知识 0720
  • 利用PyTorch进行模型量化
  • Android 小白菜鸟从入门到精通教程
  • php相关
  • uniapp上传功能用uni-file-picker实现
  • 【PPT笔记】1-3节 | 默认设置/快捷键/合并形状
  • Qt中的高分辨率及缩放处理