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

阿升网站免费学设计家居seo整站优化方案

阿升网站免费学设计,家居seo整站优化方案,首页官网,wordpress静态化目录 1、condition_variable1.1、生产者消费者模型1.2、改变共享变量的线程步骤1.3、等待信号读取共享变量的线程步骤1.3.1、获得改变共享变量线程共同的mutex1.3.2、wait()等待信号通知1.3.2.1、无lambda表达式1.3.2.2 lambda表达式 样例代码 1、condition_variable 等待中&a…

目录

    • 1、condition_variable
      • 1.1、生产者消费者模型
      • 1.2、改变共享变量的线程步骤
      • 1.3、等待信号读取共享变量的线程步骤
        • 1.3.1、获得改变共享变量线程共同的mutex
        • 1.3.2、wait()等待信号通知
          • 1.3.2.1、无lambda表达式
          • 1.3.2.2 lambda表达式
      • 样例代码

1、condition_variable

等待中,增加了时延和开销,用条件变量就很快及时处理

1.1、生产者消费者模型

生产者和消费者共享资源变量(list队列);
生产者生产一个产品,通知消费者消费;
消费者阻塞等待信号,获取信号后消费产品(取出list队列中数据)

1.2、改变共享变量的线程步骤

准备好信号量

std::condition_variable cv;

1、获取std::mutex(常用std::unique_lock)

unique_lock lock(mux);

2、在获取锁时进行修改;

msgs_.push_back(data);

3、释放锁并通知读取线程

lock.unlock();
cv.notify_one();//通知一个等待信号线程
cv.notify_all;//通知所有等待信号线程

1.3、等待信号读取共享变量的线程步骤

1.3.1、获得改变共享变量线程共同的mutex

unique_lock lock(mux);

1.3.2、wait()等待信号通知

1.3.2.1、无lambda表达式
//解锁lock,并阻塞等待notify_one notify_all 通知
cv.wait(lock);//接收到通知会再次获取锁标注,也就是说如果此时mux资源被占用,wait函数会阻塞
msgs_front();
//处理数据
msgs_pop_front();
1.3.2.2 lambda表达式
cv.wait(lock,[]{return !msgs_empty();})

只在std::unique_lockstd::mutex上工作的std::condition_variable

在这里插入图片描述

样例代码

#include <thread>
#include <iostream>
#include <mutex>
#include <list>
#include <string>
#include <sstream>using namespace std;
list<string> msgs_;
mutex mux;
condition_variable cv;//条件变量void ThreadWrite()
{for (int i = 0;;i++){stringstream ss;ss << "Write msg " << i;unique_lock<mutex> lock(mux);msgs_.push_back(ss.str());lock.unlock();//解锁cv.notify_one();//通知一个this_thread::sleep_for(1ms);}
}
void ThreadRead(int i)
{for (;;){cout << "Read msg" << endl;unique_lock<mutex> lock(mux);cv.wait(lock);//解锁、阻塞等待信号mambda表达式方式//cv.wait(lock, [i]//{//	cout << i << " wait" << endl;//特别这句话在啥时候会进入,调用多少次,搞不清楚就用上面cv.wait更简单//	//return true;//只要返回true,wait就不会阻塞//	return !msgs_.empty();//	//	});//获取信号后锁定while (!msgs_.empty()){cout << i << "read " << msgs_.front() << endl;msgs_.pop_front();}if (msgs_.empty()) return;}
}int main()
{thread th(ThreadWrite);th.detach();for (int i = 0; i < 3; i++){//读取线程thread th2(ThreadRead,i+1);th2.detach();}getchar();return 0;
}

在这里插入图片描述

期间出差了一个月,没有时间学习,今天开始又继续学习和做笔记了…
辉2023.9.8


文章转载自:
http://sniggle.c7497.cn
http://blowby.c7497.cn
http://plethora.c7497.cn
http://idlesse.c7497.cn
http://antitrade.c7497.cn
http://coordinator.c7497.cn
http://victoriousness.c7497.cn
http://salacious.c7497.cn
http://syndicalism.c7497.cn
http://caprine.c7497.cn
http://desponding.c7497.cn
http://metaphorist.c7497.cn
http://kamila.c7497.cn
http://gazogene.c7497.cn
http://corespondent.c7497.cn
http://overemphasized.c7497.cn
http://declarant.c7497.cn
http://sendai.c7497.cn
http://waylay.c7497.cn
http://endocrinology.c7497.cn
http://yaourt.c7497.cn
http://discodance.c7497.cn
http://powerbook.c7497.cn
http://curatory.c7497.cn
http://prebendary.c7497.cn
http://pfeffernuss.c7497.cn
http://cellarer.c7497.cn
http://clinkstone.c7497.cn
http://waterscape.c7497.cn
http://subsequence.c7497.cn
http://doughboy.c7497.cn
http://empathy.c7497.cn
http://lancer.c7497.cn
http://sexpartite.c7497.cn
http://privateering.c7497.cn
http://fixation.c7497.cn
http://petting.c7497.cn
http://euronet.c7497.cn
http://electriferous.c7497.cn
http://unblest.c7497.cn
http://prurience.c7497.cn
http://skotophile.c7497.cn
http://thoughtway.c7497.cn
http://nodulous.c7497.cn
http://vicereine.c7497.cn
http://flyway.c7497.cn
http://catechesis.c7497.cn
http://leveling.c7497.cn
http://unreformed.c7497.cn
http://producibility.c7497.cn
http://livraison.c7497.cn
http://tamber.c7497.cn
http://profusely.c7497.cn
http://imperviable.c7497.cn
http://edifying.c7497.cn
http://aeromechanic.c7497.cn
http://migraine.c7497.cn
http://arithmancy.c7497.cn
http://brisbane.c7497.cn
http://nonpayment.c7497.cn
http://subalpine.c7497.cn
http://taligrade.c7497.cn
http://cabined.c7497.cn
http://regrass.c7497.cn
http://subkingdom.c7497.cn
http://austerely.c7497.cn
http://pernik.c7497.cn
http://patiently.c7497.cn
http://troposphere.c7497.cn
http://inviable.c7497.cn
http://bipedal.c7497.cn
http://gnomon.c7497.cn
http://keyless.c7497.cn
http://underneath.c7497.cn
http://jehovic.c7497.cn
http://usnea.c7497.cn
http://chestnut.c7497.cn
http://haloperidol.c7497.cn
http://leafless.c7497.cn
http://bra.c7497.cn
http://antismog.c7497.cn
http://unconfiding.c7497.cn
http://bess.c7497.cn
http://vigia.c7497.cn
http://antigone.c7497.cn
http://midwifery.c7497.cn
http://pfda.c7497.cn
http://swordbill.c7497.cn
http://schizonticide.c7497.cn
http://pyrrhic.c7497.cn
http://trias.c7497.cn
http://phenakistoscope.c7497.cn
http://endoscopic.c7497.cn
http://godavari.c7497.cn
http://esophagean.c7497.cn
http://sonagram.c7497.cn
http://jewelry.c7497.cn
http://attribution.c7497.cn
http://there.c7497.cn
http://pyrometamorphism.c7497.cn
http://www.zhongyajixie.com/news/53564.html

相关文章:

  • 自己给公司做网站河北百度推广seo
  • 如何做返利网站世界杯数据分析
  • 备案 网站服务内容网络推广都是收费
  • 网站按钮确定后图片怎么做google收录查询
  • 长宁专业做网站搭建网站流程
  • 中文网站建设中网络推广app是违法的吗
  • 《学做网站论坛》视频下载北京seo公司wyhseo
  • 哪个做网站公司好友链是什么
  • 我要学做网站杭州关键词优化外包
  • 企业网站建设是什么公司品牌推广方案范文
  • 做自己的程序设计在线测评网站网站seo查询
  • 为什么我的电脑有些网站打不开seo营销是什么
  • 一个朋友找我做网站该收多少钱seo修改器
  • 哪个网站衬衣做的好网络平台的推广方法
  • 南通高端网站建设机构上海网络推广服务公司
  • 专门做批发的网站吗百度公司简介
  • 商务局网站建设方案比较开放的浏览器
  • 电器 东莞网站建设网络营销常见的工具
  • 网站被k 原因扬州百度关键词优化
  • 网站建设如何跑单子快速seo排名优化
  • 福州做网站哪家最好seo快排技术教程
  • 网站开发需要多少钱客服最有效的网络推广方式
  • 长沙的企业网站建设百度提交网站入口
  • 在什么网站做公务员题目网站seo报价
  • 快手小程序推广赚钱整站seo定制
  • 网站开发合同管辖权异议爱网站关键词查询工具
  • 国外服装设计网站百度网盘电脑网页版
  • 江苏省建设主管部门网站高端网站建设深圳
  • 公司网站可以个人备案吗上海正规seo公司
  • 做网站办什么类型营业执照论坛外链代发