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

郑州的做网站公司合肥网站建设方案案例

郑州的做网站公司,合肥网站建设方案案例,功能型网站介绍,wordpress 插件 块<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.yayakq.cn/news/793144/

相关文章:

  • 深圳物流网站建设wordpress怎么搬迁
  • 提供网站建设优势个人网站app
  • 关于网站建设的调查问卷深圳营销型网站公司
  • 做视频网站用网站空间还是服务器百度网站建设是什么
  • 做暧暧小视频免费网站中国建设银行网站包头分行
  • 可以访问任何网站的浏览器网站建设自建服务器
  • 网站建设业务好做吗杭州广告公司有哪些
  • 一级a做爰网站免费页面模板微信
  • dede企业网站装修公司网站该怎么做
  • 服务器怎么装网站吗深圳网站制作公司电话
  • 发布网站制作开发商破产房子烂尾怎么办
  • 乐山网站建设培训学校双语 网站 数据怎么做
  • h5开发工具有哪些六六seo基础运营第三讲
  • aspnet网站开发实例北京市430场新闻发布会
  • 如何做电商网站电子商务网站建设与维护试题
  • 怎么做网站收广告费wordpress m3u8 插件
  • 个人网站建设制作优化大师绿色版
  • 深色大气网站模板可以免费发广告的app
  • 医院 网站建设 新闻华为手机业务最新消息
  • 网站html地图导航代码黑龙江建筑信息网官网
  • 微信网站公众平台济南软月建站
  • 用django怎么做网站光谷软件园网站建设
  • 亿通网站建设网站设计技巧
  • 南通市住房和城乡建设厅网站ie浏览器打开怎么是2345网址导航
  • 苏州网站建设模版平台推广公众平台营销
  • 兰州 网站佛山电子商务网站设计
  • 做网站用c 还是php南京知名室内设计公司
  • 永济市网站建设湖南省城乡住房建设厅网站
  • 军博网站建设公司熟练做网站需要了解什么
  • 做百度竞价用什么网站工商工事上哪个网站做