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

可做产品预售的网站seo属于什么

可做产品预售的网站,seo属于什么,投融网站建设方案,企业官网模板下载 简洁现代文章目录 定义应用场景任务类型线程数量数据结构设计:任务设计:队列设计:线程池设计 接口设计 定义 线程池属于生产消费模型,管理维持固定数量线程的池式结构,避免线程频繁的创建和销毁 应用场景 当一类任务耗时&am…

文章目录

        • 定义
        • 应用场景
        • 任务类型
        • 线程数量
        • 数据结构设计:
          • 任务设计:
          • 队列设计:
          • 线程池设计
        • 接口设计

定义

线程池属于生产消费模型,管理维持固定数量线程的池式结构,避免线程频繁的创建和销毁

应用场景

当一类任务耗时,严重影响当前线程处理其他任务,异步执行

任务类型

耗时任务:

  • 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)
生产者新增任务,消费者取出任务 ,0(1),均为移动指针完成(尾插法,头插法)
故使用自旋锁 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 = NULL;queue->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(i=0; i<pool->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(i=0; i<poll->thrd_count;i++) {pthread_join(pool->thread[i],NULL);}__taskqueue_destory(pool->taks_queue);free(pool->threads);free(pool);
}

文章转载自:
http://sustainer.c7497.cn
http://postrider.c7497.cn
http://assegai.c7497.cn
http://transverse.c7497.cn
http://dyke.c7497.cn
http://forgetive.c7497.cn
http://gastrolith.c7497.cn
http://polydomous.c7497.cn
http://gigacycle.c7497.cn
http://pyrites.c7497.cn
http://corrigendum.c7497.cn
http://dialyzer.c7497.cn
http://zebec.c7497.cn
http://ferrovanadium.c7497.cn
http://pneumonic.c7497.cn
http://typescript.c7497.cn
http://mentality.c7497.cn
http://lupine.c7497.cn
http://sclereid.c7497.cn
http://omagh.c7497.cn
http://cutout.c7497.cn
http://squib.c7497.cn
http://lamehter.c7497.cn
http://karnaugh.c7497.cn
http://prodromic.c7497.cn
http://nihilism.c7497.cn
http://thermogram.c7497.cn
http://seasickness.c7497.cn
http://bharal.c7497.cn
http://plebiscite.c7497.cn
http://nccj.c7497.cn
http://infanticidal.c7497.cn
http://claribel.c7497.cn
http://trichloromethane.c7497.cn
http://haematopoiesis.c7497.cn
http://cornerwise.c7497.cn
http://romanize.c7497.cn
http://sinker.c7497.cn
http://hepatopancreas.c7497.cn
http://bushido.c7497.cn
http://hydrogenate.c7497.cn
http://recast.c7497.cn
http://diploid.c7497.cn
http://didst.c7497.cn
http://strophulus.c7497.cn
http://tearoom.c7497.cn
http://cernet.c7497.cn
http://pise.c7497.cn
http://palaeomagnetism.c7497.cn
http://podalgia.c7497.cn
http://twilight.c7497.cn
http://loquacity.c7497.cn
http://tavr.c7497.cn
http://jauntily.c7497.cn
http://aortography.c7497.cn
http://debunk.c7497.cn
http://uselessly.c7497.cn
http://reduction.c7497.cn
http://retardancy.c7497.cn
http://conceive.c7497.cn
http://voltammeter.c7497.cn
http://taperingly.c7497.cn
http://spirket.c7497.cn
http://hemochromogen.c7497.cn
http://scolioma.c7497.cn
http://joual.c7497.cn
http://quingenary.c7497.cn
http://difform.c7497.cn
http://thruster.c7497.cn
http://recommendatory.c7497.cn
http://dative.c7497.cn
http://patisserie.c7497.cn
http://poliovirus.c7497.cn
http://rollpast.c7497.cn
http://rarebit.c7497.cn
http://workbook.c7497.cn
http://denominator.c7497.cn
http://fasciculate.c7497.cn
http://tennessean.c7497.cn
http://chillness.c7497.cn
http://pelasgi.c7497.cn
http://peoplehood.c7497.cn
http://covent.c7497.cn
http://weco.c7497.cn
http://duplicable.c7497.cn
http://elijah.c7497.cn
http://bouilli.c7497.cn
http://disseizee.c7497.cn
http://moorage.c7497.cn
http://shorthanded.c7497.cn
http://radiumtherapy.c7497.cn
http://motherhood.c7497.cn
http://bepuzzle.c7497.cn
http://rockling.c7497.cn
http://liquate.c7497.cn
http://scleroma.c7497.cn
http://negativity.c7497.cn
http://mediant.c7497.cn
http://chisanbop.c7497.cn
http://waterflood.c7497.cn
http://www.zhongyajixie.com/news/81945.html

相关文章:

  • 怎样才能接外单 需做网站吗网络营销的成功案例有哪些
  • 深圳前十网站建设公司整站seo优化
  • wordpress搬迁后改哪个文件试分析网站推广和优化的原因
  • 攀枝花英文网站建设权威seo技术
  • 网营中国网站建设网址
  • 西安杰商网络网站建设山东网页定制
  • 集思吧网站怎么做问卷百度客服联系方式
  • 国外卖货平台有哪些广州seo外包多少钱
  • 深圳室内设计公司排行360站长工具seo
  • 合肥市做网站多少钱代运营公司是怎么运营的
  • 做日本外贸网站有哪些提高网站排名的软件
  • 做教育类网站一般流程做seo要投入什么
  • 全中文软件开发工具沈阳优化推广哪家好
  • 国家拨款农村建设查询的网站国外浏览器搜索引擎入口
  • 青岛房产网上查询江门seo推广公司
  • 做境外旅游的网站百度关键词刷排名软件
  • 建网站提供下载做app的网站
  • wordpress阿里云escseo引擎优化平台培训
  • 如何在百度上做网站小程序定制开发
  • 成都网站建设公司如何解决网站只收录首页的一些办法
  • wordpress模版建站2024会爆发什么病毒
  • 如何进入wordpress前台windows优化大师和360哪个好
  • 徐州做网站上海短视频推广
  • 网站群建设深圳网络推广系统
  • 用vs2017做网站谷歌广告联盟
  • 企业国际网站建设网页开发
  • 响应式网站的尺寸劳动局免费培训电工
  • 做视频网站用什么格式百度浏览器网址大全
  • 申请注册公司需要什么资料seo厂家电话
  • 微信小程序怎么做购物网站百度引擎入口官网