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

厦门网站建设厦门seo长尾关键词查询

厦门网站建设厦门seo,长尾关键词查询,专业的个人网站建设哪家,信阳网站建设公司<syncstream>是C20中新增加的头文件&#xff0c;提供了对同步输出流的支持&#xff0c;即在多个线程中可安全地进行输出操作&#xff0c;此头文件是Input/Output库的一部分。包括&#xff1a; 1.std::basic_syncbuf&#xff1a;是std::basic_streambuf的包装器(wrapper)&…

      <syncstream>是C++20中新增加的头文件,提供了对同步输出流的支持,即在多个线程中可安全地进行输出操作,此头文件是Input/Output库的一部分。包括:

      1.std::basic_syncbuf:是std::basic_streambuf的包装器(wrapper),它将输出累积在其自己的内部缓冲区中,并在销毁时以及明确请求时将其全部内容自动传输到包装的缓冲区,以便它们显示为连续的字符序列。此类模板主要用于创建与多线程程序无缝协作的自定义流类。如果多个线程试图同时写入同一个流,std::basic_syncbuf将确保每个线程的输出都以正确的顺序写入流,而不会出现任何交错。

using syncbuf  = basic_syncbuf<char>;
using wsyncbuf = basic_syncbuf<wchar_t>;

      2.std::basic_osyncstream:是std::basic_syncbuf的便捷包装器。它提供了一种机制来同步写入同一流的线程。

using osyncstream  = basic_osyncstream<char_t>;
using wosyncstream = basic_osyncstream<wchar_t>;

      测试代码如下:

namespace {void func1(int id, std::ostream& sync_out)
{std::osyncstream sync_stream(sync_out);sync_stream << "thread " << id << " is running" << std::endl;
}void func2(int id, std::ostream& out)
{out << "thread " << id << " is running" << std::endl;
}void sync(std::ofstream& file_out)
{std::syncbuf sync_buf(file_out.rdbuf());std::ostream sync_out(&sync_buf);constexpr int num_threads{ 10 };std::vector<std::thread> threads;for (int i = 0; i < num_threads; ++i)threads.emplace_back(func1, i, std::ref(sync_out));for (auto& t : threads)t.join();
}void common(std::ofstream& file_out)
{constexpr int num_threads{ 10 };std::vector<std::thread> threads;for (int i = 0; i < num_threads; ++i)threads.emplace_back(func2, i, std::ref(file_out));for (auto& t : threads)t.join();
}} // namespaceint test_syncstream()
{
#ifdef _MSC_VERstd::ofstream file_out1("../../../testdata/output1.txt");std::ofstream file_out2("../../../testdata/output2.txt");
#elsestd::ofstream file_out1("testdata/output1.txt");std::ofstream file_out2("testdata/output2.txt");
#endifif (!file_out1 || ! file_out2) {std::cerr << "fail to open file for writing" << std::endl;return -1;}sync(file_out1);common(file_out2);file_out1.close();file_out2.close();return 0;
}

      执行结果如下图所示:每次输出并不完全一致:output2.txt中输出是乱的,而output1.txt中的输出是正常的

      GitHub:https://github.com/fengbingchun/Messy_Test

http://www.hkea.cn/news/148785/

相关文章:

  • 台州外贸网站建设百度推广费用多少
  • 虚拟机怎么做网站空间培训班管理系统 免费
  • wordpress离线文章发布郑州seo关键词排名优化
  • 龙岗区网站建设中国职业培训在线
  • 南山网站建设外包优化网站
  • 个人怎么做网站推广神起网络游戏推广平台
  • 做网站的关键技术运营推广的方式和渠道有哪些
  • jsp做就业网站网推项目
  • 网站开发的目的和意义重庆seo排名电话
  • 顺义专业建站公司最有效的线上推广方式
  • 大连网站网站搭建制作百度识图 上传图片
  • 给人做网站多少钱黑科技引流推广神器怎么下载
  • 沈阳做网站最好的公司百度快照怎么删除
  • 设置本机外网ip做网站网站免费制作平台
  • 有什么推荐做简历的网站2024的新闻有哪些
  • 申请做网站 论坛版主惠州seo外包服务
  • 网站照片上传不了域名解析ip
  • 胖小七网站建设2022最新国际新闻10条简短
  • wordpress 网站备份厦门seo外包服务
  • 网站建设及推广培训杭州百度快照优化排名
  • 简单手机网站开发软件关键词排名代发
  • visio画网站开发类图注册域名后怎么建网站
  • 道里网站运营培训北京网络营销咨询公司
  • 目前做网站流行的语言seo关键词排名优化哪家好
  • 长沙营销型网站制作费用seo图片优化
  • 学生诚信档案建设网站seo数据分析
  • 北京住房城乡建设厅网站首页1688官网入口
  • 网站建设需要懂什么软件徐州百度seo排名优化
  • wordpress网站样式网站排名查询
  • 郑州网站建设推销外贸网站推广与优化