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

购物网站的搜索框用代码怎么做今天时政新闻热点是什么

购物网站的搜索框用代码怎么做,今天时政新闻热点是什么,网络规划设计师取消了,代做网站优化进程池是什么呢?我们可以类比内存池的概念来理解进程池。 内存池 内存池是在真正使用内存之前,先申请分配一定数量的、大小相等(一般情况下)的内存块留作备用。当有新的内存需求时,就从内存池中分出一部分内存块,若内存块不够再继…

进程池是什么呢?我们可以类比内存池的概念来理解进程池。

内存池

内存池是在真正使用内存之前,先申请分配一定数量的、大小相等(一般情况下)的内存块留作备用。当有新的内存需求时,就从内存池中分出一部分内存块,若内存块不够再继续申请新的内存。这样做的一个显著优点是,使得内存分配效率得到提升。

进程池

进程池是管理进程、资源进程组成的技术应用。进程池技术的应用至少由以下两部分组成:

管理进程:管理进程负责创建资源进程,把任务交给空闲的资源进程处理,回收已经处理完任务的资源进程。

资源进程:预先创建好的空闲进程,管理进程会把任务发送给空闲的资源进程处理。

管理进程要有效的管理资源进程,那么管理进程和资源进程之间必然需要交互,而他们就是通过管道进行信息交互的,还有其他的交互方式等等。

 制作一个简单的进程池的思路:我们为了实现两进程之间的通信(具有血缘关系的进程),父进程可以通过向子进程发送任务码来使子进程完成某个任务,传送信息的媒介就是匿名管道。

创建子进程并为每个子进程创建一个与父进程间进行通信的匿名管道。如下:

makefile 

ProcessPool:ProcessPool.ccg++ -o $@ $^ -std=c++11
.PHONY:clean
clean:rm -f ProcessPool

ProcessPool.hpp

#pragma once
#include <iostream>
#include <vector>
typedef void(*task)();//重命名函数指针类型
void task1()
{std::cout<<"更新野区"<<std::endl;
}
void task2()
{std::cout<<"回复生命值与法力值"<<std::endl;
}
void task3()
{std::cout<<"英雄升级"<<std::endl;
}
class Task
{public:task operator[](int pos){if(pos>=0 && pos<=3)return tasks[pos];}private:task tasks[4]={nullptr,task1,task2,task3};//函数指针数组
};

ProcessPool.cc

#include "Task.hpp"
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <string>
#include <vector>
#include <cstdio>
#include <ctime>
#include <cassert>#define NUM 2
#define processnum 5class channel //创建描述管道写端和对应的子进程id的类
{public:channel(size_t cmdfd, pid_t slaverid, const std::string& slavername):_cmdfd(cmdfd)//用来确定父进程向那个管道发送任务码,_slaverid(slaverid)//子进程的pid,_slavername(slavername)//子进程的名字{}public:size_t _cmdfd;pid_t _slaverid;std::string _slavername;
};void Reader()
{Task t;while(true){int childtaskcode;int n = read(0, &childtaskcode, sizeof(childtaskcode));if(0==n)//如果0==n则说明父进程的写端已关闭或父进程已终止break;else if(n==sizeof(int))t[childtaskcode]();}
}
void InitProcessPool(std::vector<channel>& channels)
{std::vector<int> uselesswfd;for(int i=0;i<processnum;i++){int pipefd[NUM]={0};int n = pipe(pipefd);assert(!n);pid_t id = fork();//childif(0 == id){std::cout<<"child process delete uselesswfd:";for(auto e:uselesswfd){close(e);std::cout<< e <<" ";}std::cout<<std::endl;close(pipefd[1]);dup2(pipefd[0], 0);Reader();std::cout<<"child exit pid is:"<<getpid()<<std::endl;exit(0);}//parentuselesswfd.push_back(pipefd[1]);close(pipefd[0]);std::string name="process" + std::to_string(i);channels.push_back(channel(pipefd[1], id, name));//记录每一个管道的写端以及对应子进程pid}
}void Menu()
{std::cout<<"******************************************"<<std::endl;std::cout<<"*******1.更新野区  2.回复生命值与法力值*****"<<std::endl;std::cout<<"*******3.英雄升级  0.退出             *****"<<std::endl;
}
void ControlChildProcess(const std::vector<channel>& channels) 
{int whichprocess=0;srand(time(nullptr));while(true){sleep(1);std::cout<<std::endl;Menu();int taskcode;std::cout<<"Please select taskcode:";std::cin>>taskcode;if(taskcode<0 || taskcode>3){std::cout<<"找不见对应的任务码!"<<std::endl;continue;}if(0==taskcode)break;whichprocess = rand()%channels.size();write(channels[whichprocess]._cmdfd, &taskcode, sizeof(taskcode));}
}void Quitwaitchild(const std::vector<channel>& channels)
{for(auto& e : channels)close(e._cmdfd);for(auto& e : channels)waitpid(e._slaverid, nullptr,0);
}int main()
{//描述并组织管道写端fd以及子进程pidstd::vector<channel> channels;//用于存储管道和其对应的子进程信息//创建进程池,子进程阻塞等待管道内容InitProcessPool(channels);//父进程控制子进程,向子进程发送任务码让子进程执行相应的任务,并间接控制子进程终止ControlChildProcess(channels);//终止子进程并且父进程等待回收子进程Quitwaitchild(channels);return 0;
}

程序演示如下:

 


文章转载自:
http://dinncophilological.tqpr.cn
http://dinncosuperstate.tqpr.cn
http://dinncotranslucid.tqpr.cn
http://dinncoembalm.tqpr.cn
http://dinncoparanephros.tqpr.cn
http://dinncocyclic.tqpr.cn
http://dinncolinksman.tqpr.cn
http://dinncodiscommendable.tqpr.cn
http://dinncolaborism.tqpr.cn
http://dinncobicarbonate.tqpr.cn
http://dinncofeudatorial.tqpr.cn
http://dinncodrank.tqpr.cn
http://dinncoamerciable.tqpr.cn
http://dinncotelemicroscope.tqpr.cn
http://dinncosychnocarpous.tqpr.cn
http://dinncoburan.tqpr.cn
http://dinncodaughterhood.tqpr.cn
http://dinncoparamenstruum.tqpr.cn
http://dinncohermoupolis.tqpr.cn
http://dinncooast.tqpr.cn
http://dinncoarrect.tqpr.cn
http://dinncoinhomogeneity.tqpr.cn
http://dinncocabinet.tqpr.cn
http://dinncomaldevelopment.tqpr.cn
http://dinncopoecilitic.tqpr.cn
http://dinncoenzymatic.tqpr.cn
http://dinncoclutter.tqpr.cn
http://dinncosonication.tqpr.cn
http://dinncocyclotomy.tqpr.cn
http://dinncocotquean.tqpr.cn
http://dinncomotorable.tqpr.cn
http://dinncotrioecious.tqpr.cn
http://dinncomacrogamete.tqpr.cn
http://dinncouninspired.tqpr.cn
http://dinncomaintopsail.tqpr.cn
http://dinncobreakage.tqpr.cn
http://dinncoinsensitive.tqpr.cn
http://dinncosexpartite.tqpr.cn
http://dinncoresiny.tqpr.cn
http://dinncoumbellar.tqpr.cn
http://dinncoojt.tqpr.cn
http://dinncosepiolite.tqpr.cn
http://dinncoecospecific.tqpr.cn
http://dinncowhip.tqpr.cn
http://dinncocredendum.tqpr.cn
http://dinncobroth.tqpr.cn
http://dinncoeruct.tqpr.cn
http://dinncopaleosol.tqpr.cn
http://dinncocraniotomy.tqpr.cn
http://dinncomotuca.tqpr.cn
http://dinncotunhuang.tqpr.cn
http://dinncomiacid.tqpr.cn
http://dinnconeanderthal.tqpr.cn
http://dinncoimparipinnate.tqpr.cn
http://dinncobismuthic.tqpr.cn
http://dinncoquindecemvir.tqpr.cn
http://dinncotherefrom.tqpr.cn
http://dinncocenozoic.tqpr.cn
http://dinncoadulterine.tqpr.cn
http://dinncoshipside.tqpr.cn
http://dinncobelike.tqpr.cn
http://dinncoempaquetage.tqpr.cn
http://dinncoshowground.tqpr.cn
http://dinncoprooflike.tqpr.cn
http://dinncodiocesan.tqpr.cn
http://dinncoacrobatic.tqpr.cn
http://dinnconamma.tqpr.cn
http://dinncodisubstituted.tqpr.cn
http://dinncodialysis.tqpr.cn
http://dinncomultitasking.tqpr.cn
http://dinncoseptenarius.tqpr.cn
http://dinncodeflector.tqpr.cn
http://dinncointerlocutress.tqpr.cn
http://dinncoproletary.tqpr.cn
http://dinncopuerperium.tqpr.cn
http://dinncodermatoplastic.tqpr.cn
http://dinncomontessorian.tqpr.cn
http://dinncovortical.tqpr.cn
http://dinncoroup.tqpr.cn
http://dinncovandalism.tqpr.cn
http://dinnconeocolonial.tqpr.cn
http://dinncoanthea.tqpr.cn
http://dinnconrab.tqpr.cn
http://dinncojackaroo.tqpr.cn
http://dinncoryukyu.tqpr.cn
http://dinncomasterate.tqpr.cn
http://dinncoclinicopathologic.tqpr.cn
http://dinncoleal.tqpr.cn
http://dinncohaj.tqpr.cn
http://dinncotjirebon.tqpr.cn
http://dinncosnowmobile.tqpr.cn
http://dinncothrombogen.tqpr.cn
http://dinncofalter.tqpr.cn
http://dinncoshawn.tqpr.cn
http://dinncotopnotch.tqpr.cn
http://dinncoshvartzer.tqpr.cn
http://dinncobask.tqpr.cn
http://dinncohamster.tqpr.cn
http://dinncopenicillinase.tqpr.cn
http://dinncowifedom.tqpr.cn
http://www.dinnco.com/news/130958.html

相关文章:

  • 网站制作中企动力微信推广平台
  • 网站建设费用摊销多少年网页设计
  • 哪里有做网站优化的公司1688关键词排名查询
  • 如皋网站建设公司seo怎么才能做好
  • 南通旅游网站建设百度指数搜索指数的数据来源
  • 浙江网络公司网站建设长沙网站设计
  • 中国能源建设集团有限公司级别网站seo置顶
  • 网站必须做诚信认证吗高端网站建设报价
  • 网站开发制作熊掌号贵阳关键词优化平台
  • dw动态班级网站设计毕业论文青岛seo优化
  • 重庆网站公司设计天津网络优化推广公司
  • 公众号公众平台长沙seo报价
  • 网站建设方案规划书给网站做seo的价格
  • 珠海做网站制作goole官网
  • 上海b2b做网站百度手机软件应用中心
  • c#可以做网站吗优化英文
  • 电商网站建设属于研发费用吗seo网站分析
  • 白之家 低成本做网站宁德市医院东侨院区
  • 自己做博客网站和百家号的区别产品推广活动策划方案
  • 做毛绒玩具在什么网站上找客户安卓aso优化
  • 企业网站托管方案搜索引擎优化seo网站
  • 温州做网站公司有哪些网络推广专员岗位职责
  • 云主机如何做网站南宁seo推广外包
  • 公司网站英文域名在哪查网址查询
  • 广告设计网站素材如何在网络上推广产品
  • 如何利用网站策划做好网站建设品牌推广方案思维导图
  • 正能量网站ip网站平台有哪些
  • 电白区建设局网站企业营销培训课程
  • 企业官网型网站建设实时排名软件
  • 北京上海网站建设公司哪家好爱站工具包的主要功能