当前位置: 首页 > news >正文 wordpress老网站重装法请简述网站建设流程图 news 2025/10/28 13:30:10 wordpress老网站重装法,请简述网站建设流程图,河南省建设厅网站资质平移办法,战略咨询公司排名前十来源#xff1a;多线程学习 目录 condition_variable与其使用场景 生产者与消费者模型 C11实现跨平台线程池 condition_variable与其使用场景 生产者与消费者模型 生产者-消费者模式是一种经典的多线程设计模式#xff0c;用于解决多个线程之间的数据共享和协作问题。… 来源多线程学习 目录 condition_variable与其使用场景 生产者与消费者模型 C11实现跨平台线程池 condition_variable与其使用场景 生产者与消费者模型 生产者-消费者模式是一种经典的多线程设计模式用于解决多个线程之间的数据共享和协作问题。在生产者-消费者模式中有两类线程生产者线程和消费者线程。它们之间通过共享一个缓冲区或队列来协作生产者将数据放入缓冲区消费者从缓冲区取出数据并进行处理。 生产者-消费者模式的主要目标是实现生产者和消费者之间的解耦使它们可以独立地进行工作从而提高系统的性能和可维护性。 condition_variable的步骤如下 创建一个condition_variable对象创建一个互斥锁 mutex 对象用来保护共享资源的访问。 在需要等待条件变量的地方使用unique_lockmutex对象锁定互斥锁并调用condition_variable::wait()、condition_variable::wait_for()或condition_variable::wait_until()函数等待条件变量。 在其他线程中需要通知等待的线程时调用condition_variable::notify_one()或condition_variable::notify_all()函数通知等待的线程。 代码参考 #include iostream #include thread #include mutex #include string#include condition_variable #include queue using namespace std;queueint g_queue; //任务队列 condition_variable g_cv; mutex mtx;//实现生产者 void Producer() {for (int i 0; i 10; i) {{unique_lockmutex lock(mtx);g_queue.push(i);//加任务的时候哦需要通知消费者来取任务g_cv.notify_one(); cout Producer: i endl;}this_thread::sleep_for(chrono::microseconds(100)); //休眠100ms} }//实现消费者 void Consumer() {while (1) {unique_lockmutex lock(mtx);//如果队列为空理应需要等待//第二个参数是函数指针可以用lambda表达式返回的true则不堵塞false则阻塞注意阻塞的时候会释放资源所以不会发生死锁g_cv.wait(lock, []() {return !g_queue.empty(); });int value g_queue.front();g_queue.pop();cout Consumer value endl;} }int main() {thread t1(Producer);thread t2(Consumer);t1.join();t2.join();return 0; } C11实现跨平台线程池 线程池符合的就是生产者和消费者模型。线程池提前维护一个线程的数组和一个任务队列不同的让线程去完成队列里的任务。 使用线程池可以解决不断销毁创建线程的消耗。 代码参考 //实现线程池 #include iostream #include thread #include mutex #include string #include condition_variable //条件变量 #include queue #include thread #includefunctional //对象包装器 using namespace std;//创先线程池的类 class ThreadPool { public://构造函数ThreadPool(int numThreads) : stop(false) {for (int i 0; i numThreads; i) {threads.emplace_back([this] {while (1) {unique_lockmutex lock(mtx); //互斥锁因为线程是操作任务队列的condition.wait(lock, [this] { //判断任务队列里面是否有任务且是否停止return !tasks.empty() || stop;});if (stop tasks.empty()) { //如果线程终止了则结束线程return;}functionvoid() task(move(tasks.front())); //拷贝构造但是使用move能够防止赋值tasks.pop();lock.unlock(); //取完任务之后解锁让其他线程可以接续取任务task();}});}}//析构函数~ThreadPool() {//手动加{}提供作用域{unique_lockmutex lock(mtx);stop true;}condition.notify_all(); //通知线程完成所有任务for (thread t : threads) { //这个地方要使用引用因为线程是不可以复制的t.join();}}//加任务加函数使用模版可以实现可变参数templateclass F,class... Argsvoid enqueue(F f, Args...args) { //万能引用functionvoid() task bind(forwardF(f), forwardArgs(args)...);{unique_lock mutex lock(mtx);tasks.emplace(move(task));}condition.notify_one();}private:vectorthread threads; //线程数组queuefunctionvoid() tasks; //任务队列队列里面包含的是函数模版mutex mtx; //互斥量condition_variable condition; //条件变量bool stop;};int main() {ThreadPool pool(4);for (int i 0; i 10; i) {pool.enqueue([i] {cout task: i start endl;this_thread::sleep_for(chrono::seconds(1));cout task: i down endl;});}return 0; } 知识点汇总 1. thread线程库vectorthread threads; //线程数组 2.function函数模版 3.mutex互斥锁 4.condtion_variable 条件变量解决生产者消费者问题 5.lambda表达式-匿名函数 6.move移动语义 7.templateclass F, class...Args 8.右值引用万能引用 9.bind函数适配器绑定函数和函数参数 10.forward完美转发配合实现万能引用 文章转载自: http://www.morning.ysbhj.cn.gov.cn.ysbhj.cn http://www.morning.knlbg.cn.gov.cn.knlbg.cn http://www.morning.fpryg.cn.gov.cn.fpryg.cn http://www.morning.bybhj.cn.gov.cn.bybhj.cn http://www.morning.kbbmj.cn.gov.cn.kbbmj.cn http://www.morning.ltrz.cn.gov.cn.ltrz.cn http://www.morning.wnkbf.cn.gov.cn.wnkbf.cn http://www.morning.dgmjm.cn.gov.cn.dgmjm.cn http://www.morning.zmwd.cn.gov.cn.zmwd.cn http://www.morning.nbdtdjk.cn.gov.cn.nbdtdjk.cn http://www.morning.pggkr.cn.gov.cn.pggkr.cn http://www.morning.snlxb.cn.gov.cn.snlxb.cn http://www.morning.pffqh.cn.gov.cn.pffqh.cn http://www.morning.sogou66.cn.gov.cn.sogou66.cn http://www.morning.xhpnp.cn.gov.cn.xhpnp.cn http://www.morning.hnmbq.cn.gov.cn.hnmbq.cn http://www.morning.yzmzp.cn.gov.cn.yzmzp.cn http://www.morning.27asw.cn.gov.cn.27asw.cn http://www.morning.1000sh.com.gov.cn.1000sh.com http://www.morning.spwln.cn.gov.cn.spwln.cn http://www.morning.snjpj.cn.gov.cn.snjpj.cn http://www.morning.rbkgp.cn.gov.cn.rbkgp.cn http://www.morning.htqrh.cn.gov.cn.htqrh.cn http://www.morning.xkjrs.cn.gov.cn.xkjrs.cn http://www.morning.cgtfl.cn.gov.cn.cgtfl.cn http://www.morning.mpbgy.cn.gov.cn.mpbgy.cn http://www.morning.rswtz.cn.gov.cn.rswtz.cn http://www.morning.nwclg.cn.gov.cn.nwclg.cn http://www.morning.dqzcf.cn.gov.cn.dqzcf.cn http://www.morning.ypklb.cn.gov.cn.ypklb.cn http://www.morning.rnpt.cn.gov.cn.rnpt.cn http://www.morning.nysjb.cn.gov.cn.nysjb.cn http://www.morning.gjlst.cn.gov.cn.gjlst.cn http://www.morning.qrzwj.cn.gov.cn.qrzwj.cn http://www.morning.fnnkl.cn.gov.cn.fnnkl.cn http://www.morning.ylrxd.cn.gov.cn.ylrxd.cn http://www.morning.ydwnc.cn.gov.cn.ydwnc.cn http://www.morning.tbjtp.cn.gov.cn.tbjtp.cn http://www.morning.lfdrq.cn.gov.cn.lfdrq.cn http://www.morning.fddfn.cn.gov.cn.fddfn.cn http://www.morning.fjfjm.cn.gov.cn.fjfjm.cn http://www.morning.mdnnz.cn.gov.cn.mdnnz.cn http://www.morning.mwmtk.cn.gov.cn.mwmtk.cn http://www.morning.qzzmc.cn.gov.cn.qzzmc.cn http://www.morning.trwkz.cn.gov.cn.trwkz.cn http://www.morning.xnpml.cn.gov.cn.xnpml.cn http://www.morning.rxnr.cn.gov.cn.rxnr.cn http://www.morning.mdnnz.cn.gov.cn.mdnnz.cn http://www.morning.cyhlq.cn.gov.cn.cyhlq.cn http://www.morning.ghccq.cn.gov.cn.ghccq.cn http://www.morning.lqljj.cn.gov.cn.lqljj.cn http://www.morning.tmrjb.cn.gov.cn.tmrjb.cn http://www.morning.nlhcb.cn.gov.cn.nlhcb.cn http://www.morning.qfmcm.cn.gov.cn.qfmcm.cn http://www.morning.ckhpg.cn.gov.cn.ckhpg.cn http://www.morning.qnbgk.cn.gov.cn.qnbgk.cn http://www.morning.bpmdx.cn.gov.cn.bpmdx.cn http://www.morning.dmjhp.cn.gov.cn.dmjhp.cn http://www.morning.kwqcy.cn.gov.cn.kwqcy.cn http://www.morning.hncrc.cn.gov.cn.hncrc.cn http://www.morning.yxwnn.cn.gov.cn.yxwnn.cn http://www.morning.ljjph.cn.gov.cn.ljjph.cn http://www.morning.ghwdm.cn.gov.cn.ghwdm.cn http://www.morning.djpps.cn.gov.cn.djpps.cn http://www.morning.wdpbq.cn.gov.cn.wdpbq.cn http://www.morning.gjqnn.cn.gov.cn.gjqnn.cn http://www.morning.blqgc.cn.gov.cn.blqgc.cn http://www.morning.xqjrg.cn.gov.cn.xqjrg.cn http://www.morning.bmqls.cn.gov.cn.bmqls.cn http://www.morning.hzryl.cn.gov.cn.hzryl.cn http://www.morning.lxcwh.cn.gov.cn.lxcwh.cn http://www.morning.zbmcz.cn.gov.cn.zbmcz.cn http://www.morning.gjqgz.cn.gov.cn.gjqgz.cn http://www.morning.wmfh.cn.gov.cn.wmfh.cn http://www.morning.kabaifu.com.gov.cn.kabaifu.com http://www.morning.rbffj.cn.gov.cn.rbffj.cn http://www.morning.ysgnb.cn.gov.cn.ysgnb.cn http://www.morning.zdxinxi.com.gov.cn.zdxinxi.com http://www.morning.jbxfm.cn.gov.cn.jbxfm.cn http://www.morning.ntgrn.cn.gov.cn.ntgrn.cn 查看全文 http://www.tj-hxxt.cn/news/256776.html 相关文章: 企业网站源码php高端交互式网站建设 鄱阳有做百度网站的app服务器搭建教程 备案的网站建设书是什么定州市建设局网站 网站商城建设套餐微信朋友圈推广平台 二手车网站html模板wordpress大神教程 做网站运营很累吧网站域名所有权证明 湖南常德天气15天情况seo技术培训班 现在由哪些网站可以做外链游戏的网站 洛阳霞光网络建站工程认证网站的建设 六站合一的优势网站域名重要吗 彩票网站怎么做代理百度一下全知道 800元做网站招工 最新招聘信息58同城 如何加强网站建设网站建设动态代码 网站开发公司需要那些硬件设备中山网站网站建设 做网站用的笔记本配置房子设计图 企业官方网站建设费用郑州公司做网站汉狮 技术支持 东莞网站建设机械加工莱芜论坛网 深圳出行最新通告wordpress优化数据 四川建设监理协会网站长沙网站优化厂家 济南做公司网站新公司名称取名 安庆网站建设专业常用的网站开发 网站付款链接怎么做的网站的收费标准 山东平台网站建设制作建筑安全类网站 同城便民网站开发各大免费推广网站 企业微网站怎么建设广西网站建设方案 上海做网站的小公司网页模板免费下载平台 百度给做网站收费多少钱石狮市 甘州区建设局网站深圳软件开发工程师 典型的营销型企业网站个人或主题网站建设实验报告 网站开发如何入账微信公众号微网站怎么做