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

企业网站建设的可行性分析电子商务网站建设文案

企业网站建设的可行性分析,电子商务网站建设文案,商城网站模板,做网站实例C之thread_local变量_c threadlocal-CSDN博客 thread_local简介 thread_local 是 C11 为线程安全引进的变量声明符。表示对象的生命周期属于线程存储期。 线程局部存储(Thread Local Storage,TLS)是一种存储期(storage duration),对象的存储是在…

C++之thread_local变量_c++ threadlocal-CSDN博客

thread_local简介
        thread_local 是 C++11 为线程安全引进的变量声明符。表示对象的生命周期属于线程存储期。

        线程局部存储(Thread Local Storage,TLS)是一种存储期(storage duration),对象的存储是在线程开始时分配,线程结束时回收,每个线程有该对象自己的实例;如果类的成员函数内定义了 thread_local 变量,则对于同一个线程内的该类的多个对象都会共享一个变量实例,并且只会在第一次执行这个成员函数时初始化这个变量实例。

        thread_local 一般用于需要保证线程安全的函数中。本质上,就是线程域的全局静态变量。
———————————

std::mutex print_mtx;    //避免打印被冲断thread_local int thread_count = 1;
int global_count = 1;void ThreadFunction(const std::string& name, int cpinc)
{for (int i = 0; i < 5; i++){std::this_thread::sleep_for(std::chrono::seconds(1));std::lock_guard<std::mutex> lock(print_mtx);std::cout << "thread name: " << name << ", thread_count = " << thread_count << ", global_count = " << global_count++ << std::endl;thread_count += cpinc;}
}int main()
{std::thread t1(ThreadFunction, "t1", 2);std::thread t2(ThreadFunction, "t2", 5);t1.join();t2.join();
}输出:thread name: t2, thread_count = 1, global_count = 1
thread name: t1, thread_count = 1, global_count = 2
thread name: t1, thread_count = 3, global_count = 3
thread name: t2, thread_count = 6, global_count = 4
thread name: t1, thread_count = 5, global_count = 5
thread name: t2, thread_count = 11, global_count = 6
thread name: t1, thread_count = 7, global_count = 7
thread name: t2, thread_count = 16, global_count = 8
thread name: t1, thread_count = 9, global_count = 9
thread name: t2, thread_count = 21, global_count = 10

可以看出来每个线程中的 thread_count 都是从 1 开始打印,这印证了 thread_local 存储类型的变量会在线程开始时被初始化,每个线程都初始化自己的那份实例。另外,两个线程的打印数据也印证了 thread_count 的值在两个线程中互相不影响。作为对比的 global_count 是静态存储周期,就没有这个特性,两个线程互相产生了影响。
—————————————

http://www.yayakq.cn/news/459849/

相关文章:

  • 用dw如何做网站做一下网站需要什么
  • 旅游电商网站建设方案模板网页设计页面设计主要技术
  • 安保企业网站模板太原网站建设包括什么
  • 上海网站建站烟台电子商务产业园网站建设
  • 河南省网站建设哪家好佛山大良网站建设招聘
  • 上海市建设工程 安全质量网站怎样做自己的 优惠卷网站
  • 网站建设 义乌免费域名网站申请
  • 免费注册企业网站陕西最新消息
  • 在哪个网站可以做图文合并建设网站中期要做什么
  • 工作室网站制作多多在线免费观看电视剧
  • 可以做软件的网站wordpress 如何做门户
  • 分类网站建设多少钱萧山品牌网站建设
  • 地方网站推广沈阳网站营销
  • 做商城网站会不会被攻击网站建设项目需求分析流程图
  • 怎么做网站里的资讯厦门网站建设外贸
  • 赤峰网站制作p站代理网址
  • 戴尔网站建设成功的关键百度推广价格
  • 装修公司网站建设的意义仿58网站怎么做
  • 网站主题及风格宝塔 伪静态 wordpress
  • python是做网站的吗城市建设规划网站
  • 网站 怎么做百度才能搜索出来中山做网站做的好的公司
  • 庆阳网站设计费用做外贸的网站主要有哪些
  • 如何自己建立网站在网站上如何做天气预报栏
  • 系统网站主题有哪些问题成都网站建设有哪些
  • 企业网站建设费用预算在线建设网站 源代码
  • 专业手机网站建设公司排名上海传媒公司艺人
  • 网站开发的学习方法网站建设的经济可行性分析
  • 网站的建设会计入哪个科目泊头网站建设公司
  • 网站 硬件方案网络营销的步骤和流程
  • 晋中网站seo代做百度首页排名价格