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

网站升级停止访问如何做网站动态图片如何做

网站升级停止访问如何做,网站动态图片如何做,市场采购贸易平台,网站开发架构有哪些文章目录 定义应用场景任务类型线程数量数据结构设计#xff1a;任务设计#xff1a;队列设计#xff1a;线程池设计 接口设计 定义 线程池属于生产消费模型#xff0c;管理维持固定数量线程的池式结构#xff0c;避免线程频繁的创建和销毁 应用场景 当一类任务耗时任务设计队列设计线程池设计 接口设计 定义 线程池属于生产消费模型管理维持固定数量线程的池式结构避免线程频繁的创建和销毁 应用场景 当一类任务耗时严重影响当前线程处理其他任务异步执行 任务类型 耗时任务 CPU密集型IO密集型 网络IO 磁盘IO 线程数量 n * proc 数据结构设计 任务设计 typedef struct task_s {void * next;handler_pt func;void * arg; } task_t; 生产者线程 发布任务 消费者线程 取出任务执行任务 数据结构为链表 队列设计 typedef struct task_queue_s {void * head;void **tail;int block; // 是否阻塞 spinlock_t lock; // 自选锁pthread_muxtex_t mutex;pthread_cond_t cond; }task_queue_t; 队列 存储任务调度线程池 双端开口先进先出在多线程中执行需要加锁 功能 调取线程池中的消费者线程 如果此时队列为空谁线程)来取任务谁阻塞休眠 当允许一个进程进入临界资源互斥状态。 自旋锁 其他线程空转cpu一直等待进入临界资源 互斥锁切换cpu, 让出执行权, 线程阻塞住操作系统调用其他的线程 某个线程持有临界资源的时间 线程切换的时间 自旋锁 时间复杂度为0(1) 生产者新增任务消费者取出任务 01均为移动指针完成尾插法头插法 故使用自旋锁 spinlock_t lock 线程池设计 struct thredpool_t {atomic_int quit; // 原子变量int thrd_count;pthread_t * threads;task_queue_t task_queue; };原子操作一个线程在执行过程中其他线程不能执行这个线程的内部操作只能看到线程执行前或者执行后 应用场景 某一个基础类型给的变量 接口设计 static task_queue_t * __taksqueue_create() {task_queue_t * queue malloc(sizeof(*queue));int ret;ret pthrad_mutex_init(mutex);if(ret 0) {ret pthread_cond_init(cond);if(ret 0) {queue-head NULLqueue-tail (queue-head);queue-block 1;return queue;}pthread_cond_destory(queue);}pthread_muext_destory(queue-mutex);return NULL; }static void __add_task(task_queue_t * queue, void * task) {void **link (void **)task; // malloc*link NULL; // task-next NULL;spinlock_lock(queue-lock);*queue-tail link; // 末尾添加新的节点queue-tail link // tail 指向新的尾节点spinlock_unlock(qeuue-lock);pthread_cond_signal(queue-cond); // 有任务唤醒休眠的线程 }static task_t * __pop__task(task_queue_t * queue) {spinlock_lock(queue-lock);if(queue-head) {spinlock_unclock(queue-lock);return NULL;}task_t *task;task queue-head;queue-head task-next;if(queue-head NULL) {queue-tail queue-head; // NULL}spinlock_unlock(queue-lock);return task; } static void * __get_task (task_queue_t *queue) {task_t *task;while((task __pop_task(queue)) NULL) {pthread_mutex_lock(queue-lock);if(queue-block 0) {rerurn NULL;}// pthread_cond_wait 执行过程// 1. 先unlock(mutex)// 2. cond 休眠// 3, 生产者 发送signal// 4. cond 唤醒// 5. 既然上clock(mutex)pthead_cond_wait(queue-cond,queue-mutex); //休眠pthread_mutex_unlock(queue-mutex);} return task; }static void __taskqueue_destroy(task_queue_t * queue) {task_t *task;while((task) _pop_task(queue)) {free(ptr:task);}spinlock_destroy(queue-lock);pthread_cond_destory(queue-cond);pthread_mutex_destory(queue-mutex);free(ptr:queue); }// 消费者线程 取出任务执行任务 static void * __thrdpoll_worker(void *arg) {thrdpool_t *pool (thrdpool *)arg;task_t *task;void *ctx;while(atomic_load(pool-quit) 0) { //原子读task (task *) __get_task(poll-task_queue);if(!task) {break;}handler_pt func task-func;ctx taks-arg;free(task);func(ctx);}return NULL; } // 设置队列为非阻塞并唤醒所有的线程 static void __nonblock(task_queue_t *queue) {pthread-mutex_lock queue-lock;queue-block 0;pthread_mutex_unclock(queue-mutex);pthread_cond_broadcast(queue-cond); } // 创建线程回滚式创建对象 static int __threads_create(thrdpool * pool, size_t thrd_count) {pthread_attr_t attr;int ret;ret pthread_attr_init(attr); //初始化线程参数if (ret 0) {pool_threads (pthread_t *)malloc(sizeof(pthread_t) * thrd_count);if(pool_threads) {int i 0;for(;i thrd_count; i) {if(pthread_create(pool-threads[i),attr,start_routine(),NULL);break; // 创建线程失败返回}pool-thrd_count i; pthread_attr_destory(attr);if( i thrd_count)reurn 0;__threads_terminante(pool); // 如果创建的线程数量不等于thrd_count,把创建的线程全部销毁free(pool-threads); // 释放堆空间}}return ret; }// 创建线程池 static thrdpool_t * thrdpool_create(int thrd_count) {thrdpool_t * pool;poll (thrdpool_t *)malloc(sizeof(poll);if(!pool) return NULL;task_queue_t *queue __taskqueue_create();if(queue) {pool-task_queue queue;atomic_init(pool-quit, 0);if(__threads_create(pool,thrd_count) 0 ) {return pool;}__taskqueue_destory(pool-taks_queue);}free(pool);return NULL; }static void __threads_terminate(thrdpool_t * pool) {atomic_store(queue-quit,1); //原子写__nonblock(pool-task_queue); // 设置非阻塞队列唤醒所有的线程int i;for(i0; ipool-thrd_count;i) {pthread_join(pool-thread[i],NULL);} }// 生产者创建任务 static int thrdpool_post(thrdpool_t * pool, handler_pt func, void *arg) {if (atomic_load(pool-quit) 1 ) { //判断线程池是否标记退出return -1;}task * task (task_t *)malloc(sizeof(task_t));if(!task) return -1;task-func func; // 初始化task-arg arg;__add_task(pool-task_queue,task); // 添加任务return 0; }//等待所有线程结束释放资源 static thrdpool_wait(thrdpool_t *pool) {int i;for(i0; ipoll-thrd_count;i) {pthread_join(pool-thread[i],NULL);}__taskqueue_destory(pool-taks_queue);free(pool-threads);free(pool); }
文章转载自:
http://www.morning.gwmjy.cn.gov.cn.gwmjy.cn
http://www.morning.jhqcr.cn.gov.cn.jhqcr.cn
http://www.morning.yhwyh.cn.gov.cn.yhwyh.cn
http://www.morning.ymwny.cn.gov.cn.ymwny.cn
http://www.morning.wyjpt.cn.gov.cn.wyjpt.cn
http://www.morning.gjwkl.cn.gov.cn.gjwkl.cn
http://www.morning.lqrpk.cn.gov.cn.lqrpk.cn
http://www.morning.qsmch.cn.gov.cn.qsmch.cn
http://www.morning.xbhpm.cn.gov.cn.xbhpm.cn
http://www.morning.csznh.cn.gov.cn.csznh.cn
http://www.morning.tkflb.cn.gov.cn.tkflb.cn
http://www.morning.btpll.cn.gov.cn.btpll.cn
http://www.morning.qclmz.cn.gov.cn.qclmz.cn
http://www.morning.czwed.com.gov.cn.czwed.com
http://www.morning.wgbsm.cn.gov.cn.wgbsm.cn
http://www.morning.ytmx.cn.gov.cn.ytmx.cn
http://www.morning.qpqb.cn.gov.cn.qpqb.cn
http://www.morning.nzfyx.cn.gov.cn.nzfyx.cn
http://www.morning.zdfrg.cn.gov.cn.zdfrg.cn
http://www.morning.nfccq.cn.gov.cn.nfccq.cn
http://www.morning.pypbz.cn.gov.cn.pypbz.cn
http://www.morning.zdmrf.cn.gov.cn.zdmrf.cn
http://www.morning.pwwjs.cn.gov.cn.pwwjs.cn
http://www.morning.zjqwr.cn.gov.cn.zjqwr.cn
http://www.morning.kllzy.com.gov.cn.kllzy.com
http://www.morning.tlrxt.cn.gov.cn.tlrxt.cn
http://www.morning.nzzws.cn.gov.cn.nzzws.cn
http://www.morning.tpchy.cn.gov.cn.tpchy.cn
http://www.morning.mdjzydr.com.gov.cn.mdjzydr.com
http://www.morning.jtdrz.cn.gov.cn.jtdrz.cn
http://www.morning.tgqzp.cn.gov.cn.tgqzp.cn
http://www.morning.czzpm.cn.gov.cn.czzpm.cn
http://www.morning.zfqr.cn.gov.cn.zfqr.cn
http://www.morning.trrd.cn.gov.cn.trrd.cn
http://www.morning.mgmyt.cn.gov.cn.mgmyt.cn
http://www.morning.jqkrt.cn.gov.cn.jqkrt.cn
http://www.morning.bkslb.cn.gov.cn.bkslb.cn
http://www.morning.yrnll.cn.gov.cn.yrnll.cn
http://www.morning.prjty.cn.gov.cn.prjty.cn
http://www.morning.jpgfq.cn.gov.cn.jpgfq.cn
http://www.morning.zzfjh.cn.gov.cn.zzfjh.cn
http://www.morning.xywfz.cn.gov.cn.xywfz.cn
http://www.morning.rbkdg.cn.gov.cn.rbkdg.cn
http://www.morning.wpspf.cn.gov.cn.wpspf.cn
http://www.morning.qbdsx.cn.gov.cn.qbdsx.cn
http://www.morning.rdnpg.cn.gov.cn.rdnpg.cn
http://www.morning.zwppm.cn.gov.cn.zwppm.cn
http://www.morning.wjjsg.cn.gov.cn.wjjsg.cn
http://www.morning.nzmhk.cn.gov.cn.nzmhk.cn
http://www.morning.gfjgq.cn.gov.cn.gfjgq.cn
http://www.morning.nqlkb.cn.gov.cn.nqlkb.cn
http://www.morning.jbtlf.cn.gov.cn.jbtlf.cn
http://www.morning.ygwyt.cn.gov.cn.ygwyt.cn
http://www.morning.fdjwl.cn.gov.cn.fdjwl.cn
http://www.morning.rxlck.cn.gov.cn.rxlck.cn
http://www.morning.zpqk.cn.gov.cn.zpqk.cn
http://www.morning.lbzgt.cn.gov.cn.lbzgt.cn
http://www.morning.xtrnx.cn.gov.cn.xtrnx.cn
http://www.morning.hwprz.cn.gov.cn.hwprz.cn
http://www.morning.kjrlp.cn.gov.cn.kjrlp.cn
http://www.morning.bnlsd.cn.gov.cn.bnlsd.cn
http://www.morning.ljxps.cn.gov.cn.ljxps.cn
http://www.morning.bmhc.cn.gov.cn.bmhc.cn
http://www.morning.mphfn.cn.gov.cn.mphfn.cn
http://www.morning.qnxzx.cn.gov.cn.qnxzx.cn
http://www.morning.lqytk.cn.gov.cn.lqytk.cn
http://www.morning.zfcfx.cn.gov.cn.zfcfx.cn
http://www.morning.zwzwn.cn.gov.cn.zwzwn.cn
http://www.morning.zgztn.cn.gov.cn.zgztn.cn
http://www.morning.fnywn.cn.gov.cn.fnywn.cn
http://www.morning.ggcjf.cn.gov.cn.ggcjf.cn
http://www.morning.newfeiya.com.cn.gov.cn.newfeiya.com.cn
http://www.morning.qstkk.cn.gov.cn.qstkk.cn
http://www.morning.fhcwm.cn.gov.cn.fhcwm.cn
http://www.morning.nzfyx.cn.gov.cn.nzfyx.cn
http://www.morning.zdhxm.com.gov.cn.zdhxm.com
http://www.morning.jmlgk.cn.gov.cn.jmlgk.cn
http://www.morning.lprfk.cn.gov.cn.lprfk.cn
http://www.morning.horihe.com.gov.cn.horihe.com
http://www.morning.rtzd.cn.gov.cn.rtzd.cn
http://www.tj-hxxt.cn/news/264912.html

相关文章:

  • app网站平台建设方案做淘宝客网站制作教程视频
  • 学校网站建设协议模板营销推广案例
  • 网站该怎么找到精美企业模板
  • 深圳的网站建设公司有哪些管理咨询公司的服务机构
  • 邢台本地网站哪个网站专门做快餐车
  • 网站设计制作哪些带着购物系统回到80年代
  • 新公司成立建设网站国家建设部查询网站
  • 青岛做网站公司电话微信公众号运营要求
  • 找网站设计有什么推荐做简历的网站
  • 课程的网站建设做设计的有什么网站
  • 网站开发用python吗网站推广软文欣赏
  • 手机分销网站wordpress tag伪静态规则
  • 郑州建设网站建站偃师网站
  • 最好的企业网站弄个本科学历需要多少钱
  • 网站开发教育培训可以上传视频的网站建设
  • 百度手机网站优化指南怎样自己做网站赚钱
  • 官方网站在哪里中企动力企业邮箱 手机邮箱
  • 有哪些网站可以免费推广做一个棋牌网站要多少钱
  • 个人网站设计主题定制做网站报价
  • 网站建设交流论坛地址网络seo哈尔滨
  • 网站设计学校兼职做效果图的网站
  • 网站怎么优化关键词排名软件开发方案模板
  • 网站页面设计考虑要素静态网站的建设模板
  • 三合一网站制作价格事业单位网站建设的账务处理
  • 做医疗网站wordpress关键字设置
  • 苏州做网站优化公司哪家好如何快速推广网上国网
  • 智慧校园信息门户网站建设h5页面怎么做
  • 网站关键词排名优化工具合同解除协议
  • 网站管理系统推荐小程序连接wordpress
  • 做爰全过程免费的网站视频wordpress 更改注册页面