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

固安建设局网站创建网站怎么赚钱的

固安建设局网站,创建网站怎么赚钱的,网站网站制作服务,黄页88登录死锁检测组件-设想 现在有三个临界资源和三把锁绑定了#xff0c;三把锁又分别被三个线程占用。#xff08;不用关注临界资源#xff0c;因为锁和临界资源是绑定的#xff09; 但现在出现这种情况#xff1a;线程1去申请获取锁2#xff0c;线程2申请获取锁3#xff0c;…死锁检测组件-设想 现在有三个临界资源和三把锁绑定了三把锁又分别被三个线程占用。不用关注临界资源因为锁和临界资源是绑定的 但现在出现这种情况线程1去申请获取锁2线程2申请获取锁3线程3申请获取锁1这样就会造成死锁 死锁问题可转换为有向图的环路检测 死锁的构建 有四个线程4把锁以下代码一定会产生死锁 pthread_mutex_t mtx1 PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t mtx2 PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t mtx3 PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t mtx4 PTHREAD_MUTEX_INITIALIZER;void *thread_routine_a(void *arg) {printf(thread_routine a \n);pthread_mutex_lock(mtx1);sleep(1); pthread_mutex_lock(mtx2);pthread_mutex_unlock(mtx2);pthread_mutex_unlock(mtx1);printf(thread_routine a exit\n);}void *thread_routine_b(void *arg) {printf(thread_routine b \n);pthread_mutex_lock(mtx2);sleep(1);pthread_mutex_lock(mtx3);pthread_mutex_unlock(mtx3);pthread_mutex_unlock(mtx2);printf(thread_routine b exit \n); // -----pthread_mutex_lock(mtx1); }void *thread_routine_c(void *arg) {printf(thread_routine c \n);pthread_mutex_lock(mtx3);sleep(1);pthread_mutex_lock(mtx4);pthread_mutex_unlock(mtx4);pthread_mutex_unlock(mtx3);printf(thread_routine c exit \n); }void *thread_routine_d(void *arg) {printf(thread_routine d \n);pthread_mutex_lock(mtx4);sleep(1);pthread_mutex_lock(mtx1);pthread_mutex_unlock(mtx1);pthread_mutex_unlock(mtx4);printf(thread_routine d exit \n); }int main() { #if 1init_hook();pthread_t tid1, tid2, tid3, tid4;pthread_create(tid1, NULL, thread_routine_a, NULL);pthread_create(tid2, NULL, thread_routine_b, NULL);pthread_create(tid3, NULL, thread_routine_c, NULL);pthread_create(tid4, NULL, thread_routine_d, NULL);pthread_join(tid1, NULL);pthread_join(tid2, NULL);pthread_join(tid3, NULL);pthread_join(tid4, NULL); }这里产生了线程a 线程b 线程c 线程d 》 线程a的这样一个环路 但是我们不知道哪把锁被哪个线程占用了没法构建有向图也就无法得知是否产生了这样一个环路 这时可以用hook调自己写的 pthread_mutex_lock将线程和锁的映射关系保存起来 pthread的hook 有点像装饰器模式 // 函数指针 typedef int (*pthread_mutex_lock_t)(pthread_mutex_t *mutex); pthread_mutex_lock_t pthread_mutex_lock_f;typedef int (*pthread_mutex_unlock_t)(pthread_mutex_t *mutex); pthread_mutex_unlock_t pthread_mutex_unlock_f;static int init_hook() {// RTLD_NEXT可以理解为代码段在这里面找pthread_mutex_lock函数名把地址返回// 所以pthread_mutex_lock_f就是静态或动态库里的pthread_mutex_lock锁函数 pthread_mutex_lock_f dlsym(RTLD_NEXT, pthread_mutex_lock); pthread_mutex_unlock_f dlsym(RTLD_NEXT, pthread_mutex_unlock); }int pthread_mutex_lock(pthread_mutex_t *mutex) {printf(pthread_mutex_lock selfid %ld, mutex: %p\n, pthread_self(), mutex);beforelock(pthread_self(), mutex);pthread_mutex_lock_f(mutex); // 用钩子的好处给系统函数命一个别名afterlock(pthread_self(), mutex);}int pthread_mutex_unlock(pthread_mutex_t *mutex) {printf(pthread_mutex_unlock\n);pthread_mutex_unlock_f(mutex);afterunlock(pthread_self(), mutex);} 这样在加锁的时候就能知道锁id(mutex)和线程id的对应关系 图的构建 通过邻接表实现有向图如线程1等待线程2释放锁则将线程id2挂到线程1后面 而如何知道线程1申请的锁被线程2占用了呢设置一个 mutex 和 thread的映射列表结构体数组通过mutex返回threadid。 如线程1对mutex1加锁将mutex1threadid1加入locklist中表示mutex1被线程1占用了 图的邻接表生成当前线程根据要申请的mutex a找到占用这把锁的线程id A通过映射列表将改线程追加到自己的后面 通过邻接表检测环路DFS检测过的标为1再遇到一个1就表示死锁了 那我们怎么把这个图构建起来 通过三个原语操作 beforelock、afterlock、afterrunlock 以后要用到再说吧 至此死锁检测组件设计的大致思路为通过hook保存muitex和threadid的映射关系根据这个映射关系生成线程之间的有向图邻接表再利用dfs检测图的环路
http://www.tj-hxxt.cn/news/223351.html

相关文章:

  • 下载百度网盘宁波seo品牌推广排名
  • 公司网站建设推进表汉中微信网站建设推广
  • 杭州做网站需要多少钱建设网站价钱
  • 家居企业网站建设效果网站侧边栏怎么做
  • 广州知名网站推广视频会议软件
  • 手机端seo多语言网站seo
  • 权重网站建设桂林象鼻山在哪个位置
  • 厦门做网站企业wordpress sahifa
  • 合肥网站制作QQ织梦网站模板视频
  • 网站收录工具江苏建设人才考试网二建
  • 常州中环互联网网站建设电子商务平台建设预算
  • 网站建设组织架构网上推广工作
  • jsp 企业建站男和男人怎么做那个视频网站
  • 手机访问跳转手机网站公司的宣传网站应该怎么做
  • 网站建设相关合同内容云和网站建设
  • centos架设wordpress网站建设优化加盟代理
  • 怎么做根优酷差不多的网站怎么访问被禁止的网站
  • 网站建设平台用乐云践新网上做网站接活怎么样
  • 梅州建站网络网站的建设过程
  • 中原区网站建设百度搜索大全
  • 昌吉市住房和城乡建设局网站网站和主机有什么不同
  • 珠海网站建设黄荣如何建立自己的app
  • 网站的开发公司倒闭对网站使用哪个免费的网页制作软件最好
  • 找人做ps的网站wordpress模板修改服务
  • 做公众号好还是网站好百度手机网站自助建站
  • 网站是如何建立的呢wordpress 图片循环
  • 公司网站开发费用记入什么科止佛山网站建设的市场
  • 建网站可行性分析网站制作公司嘉兴
  • 网站建设的报告分析电商平面设计岗位职责
  • 这种资源网站怎么做才赚钱韶关手机网站建站