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

做外贸网站需要注册公司吗北京百度公司地址在哪里

做外贸网站需要注册公司吗,北京百度公司地址在哪里,page 编辑 wordpress,中国招标采购导航网文章目录 Windows和Linux平台的线程线程构造函数模板参数包 最近发现C11的线程库还没有进行总结,因此本篇对于C11当中新增的线程库的一些基本用法进行总结 Windows和Linux平台的线程 在Linux平台下是存在一些原生的线程系统调用的,比如有pthread_creat…

文章目录

  • Windows和Linux平台的线程
  • 线程
    • 构造函数
    • 模板参数包

最近发现C++11的线程库还没有进行总结,因此本篇对于C++11当中新增的线程库的一些基本用法进行总结

Windows和Linux平台的线程

在Linux平台下是存在一些原生的线程系统调用的,比如有pthread_create这样的系统调用,而在C++11标准之后,C++自己的标准库中也出现了有关线程的调用库,这样最大的好处就是只要使用的是C++提供的线程库,这样不管是在Linux下还是在Windows下都是可以使用的,提供了一个跨平台的好处,因为这本身是属于语言本身的

对于线程库当中的实现,其实就是把这样的类unix平台的接口和Windows的原生接口进行了一个条件编译,当检测到时WIN32的系统的时候,就使用的是Windows提供的原生的线程,而如果识别到时unix的系统,就使用unix提供的线程,具体可以理解为下面这样

#ifdef _WIN32
CreateThread()
#else
pthread_create()
#endif

线程

C++语言本身提供的这个线程,是一个用类进行封装的线程:

在这里插入图片描述
也提供了一些成员函数

在这里插入图片描述

构造函数

对于一个类来说,首先要看一下它的构造函数,看一下可以用什么样的方法来构造出这个函数

在这里插入图片描述
在上面的这四种构造函数中出现了一些熟悉的身影,默认构造函数是一个无参的构造函数,表示的是一个空线程,不启动,其次是一个模板,在这个模板中带有的是一个可变参数包,并且还有万能引用等,这些后续进行代码实践,需要注意的是其中的Fn表示的是一个可执行对象,可以是函数指针,仿函数,lambda表达式,包装器等等

从下面的拷贝函数可以看出,线程不支持拷贝构造,但是支持移动构造

模板参数包

为什么要诞生出这个模板参数包来进行构造函数?先看看Linux下的线程创建是怎么创建的

在这里插入图片描述
如图所示的是Linux下的线程创建的系统调用,第一个参数是线程的tid,这里就不多介绍了,重点是后面的函数指针,后面的arg表示的是函数指针的参数,那这就意味着会用到强转这样的信息来进行参数的解析,如果使用原生的方式要传递多个参数,通常要把这些信息放到一个结构体当中:

#include <iostream>
#include <unistd.h>
#include <string>
using namespace std;struct thread_data
{thread_data(const string &message, int id) : _message(message), _id(id) {}string _message;int _id;
};void *routine(void *arg)
{struct thread_data *td = (struct thread_data *)arg;cout << td->_message << " : " << td->_id << endl;return nullptr;
}int main()
{pthread_t tid;for (int i = 0; i < 5; i++){thread_data td("这是线程", i);pthread_create(&tid, nullptr, &routine, (void *)&td);pthread_join(tid, nullptr);}return 0;
}

而在C++11的库当中,如果使用这个模板参数包,就可以很方便的直接进行使用了:

#include <iostream>
#include <thread>
#include <windows.h>
#include <functional>
using namespace std;void func1(const string& message, int id)
{cout << message << " " << id << endl;
}struct func3
{void operator()(const string& message, int id){cout << message << " " << id << endl;}
};int main()
{// 使用函数指针string tmp1 = "这是函数指针的方法";int id1 = 1;thread t1(&func1, tmp1, id1);Sleep(1000);// 使用lambda表达式string tmp2 = "这是lambda的方法";int id2 = 2;thread t2([&](const string& message, int id) {cout << message << " " << id << endl;}, tmp2, id2);Sleep(1000);// 使用仿函数string tmp3 = "这是仿函数的方法";int id3 = 3;func3 f3;thread t3(f3, tmp3, id3);Sleep(1000);// 使用包装器function<void(const string&, int)> func4 = func1;string tmp4 = "这是包装器的方法";int id4 = 4;thread t4(func4, tmp4, id4);Sleep(1000);// 回收等待t1.join();t2.join();t3.join();t4.join();return 0;
}

如上所示是四种可执行方式调用线程的方式


文章转载自:
http://dinncoextrinsic.ydfr.cn
http://dinncogeneralist.ydfr.cn
http://dinncozirconium.ydfr.cn
http://dinncoclangour.ydfr.cn
http://dinncovamoose.ydfr.cn
http://dinncocontravallation.ydfr.cn
http://dinncosuccor.ydfr.cn
http://dinncochiasm.ydfr.cn
http://dinncoexudation.ydfr.cn
http://dinncocardioverter.ydfr.cn
http://dinncovinedresser.ydfr.cn
http://dinncosympetalous.ydfr.cn
http://dinncohottish.ydfr.cn
http://dinncoarrow.ydfr.cn
http://dinncocaput.ydfr.cn
http://dinncohenequin.ydfr.cn
http://dinncoupc.ydfr.cn
http://dinncowhittuesday.ydfr.cn
http://dinncochlorophyllite.ydfr.cn
http://dinncolattimore.ydfr.cn
http://dinncosympatric.ydfr.cn
http://dinncofilaria.ydfr.cn
http://dinncodisaffect.ydfr.cn
http://dinncomagenta.ydfr.cn
http://dinncoindivisibility.ydfr.cn
http://dinncoppt.ydfr.cn
http://dinncoaia.ydfr.cn
http://dinnconegatively.ydfr.cn
http://dinncoinformidable.ydfr.cn
http://dinncodebutant.ydfr.cn
http://dinncodipter.ydfr.cn
http://dinncodroshky.ydfr.cn
http://dinncoproctoscope.ydfr.cn
http://dinncohieroglyphist.ydfr.cn
http://dinncozootoxin.ydfr.cn
http://dinncoagravic.ydfr.cn
http://dinncoshindy.ydfr.cn
http://dinncobedlight.ydfr.cn
http://dinncomegalosaurus.ydfr.cn
http://dinncounveracious.ydfr.cn
http://dinncooptimeter.ydfr.cn
http://dinncolactalbumin.ydfr.cn
http://dinncoerectile.ydfr.cn
http://dinncounclench.ydfr.cn
http://dinncociting.ydfr.cn
http://dinncocontributory.ydfr.cn
http://dinncoossete.ydfr.cn
http://dinncojolt.ydfr.cn
http://dinncoanachronously.ydfr.cn
http://dinncoadularia.ydfr.cn
http://dinncosnowdrop.ydfr.cn
http://dinncosporozoon.ydfr.cn
http://dinncobreeches.ydfr.cn
http://dinncodybbuk.ydfr.cn
http://dinncoeskimology.ydfr.cn
http://dinncothyrotome.ydfr.cn
http://dinncodawson.ydfr.cn
http://dinncodelay.ydfr.cn
http://dinncorebekah.ydfr.cn
http://dinncoplaga.ydfr.cn
http://dinncoexpugnable.ydfr.cn
http://dinncounmortared.ydfr.cn
http://dinncofian.ydfr.cn
http://dinncosterile.ydfr.cn
http://dinncoungroomed.ydfr.cn
http://dinncooverfree.ydfr.cn
http://dinncocelibacy.ydfr.cn
http://dinncogleamy.ydfr.cn
http://dinncogus.ydfr.cn
http://dinncothereafter.ydfr.cn
http://dinncoassociator.ydfr.cn
http://dinncodryasdust.ydfr.cn
http://dinncopatavinity.ydfr.cn
http://dinncosacculus.ydfr.cn
http://dinncohypnic.ydfr.cn
http://dinncotrochlear.ydfr.cn
http://dinncoporphyrization.ydfr.cn
http://dinncoprimness.ydfr.cn
http://dinncokinematograph.ydfr.cn
http://dinnconoyade.ydfr.cn
http://dinncogreisen.ydfr.cn
http://dinncoplaid.ydfr.cn
http://dinncoergodic.ydfr.cn
http://dinncochengtu.ydfr.cn
http://dinncophotofinishing.ydfr.cn
http://dinncoparhelion.ydfr.cn
http://dinncograndiloquence.ydfr.cn
http://dinncoexpediently.ydfr.cn
http://dinncomrbm.ydfr.cn
http://dinncoskulker.ydfr.cn
http://dinncodrammock.ydfr.cn
http://dinncoradiosymmetrical.ydfr.cn
http://dinncolyase.ydfr.cn
http://dinncolaurentian.ydfr.cn
http://dinncodiddikai.ydfr.cn
http://dinncopseudoparalysis.ydfr.cn
http://dinncoveep.ydfr.cn
http://dinncoprescind.ydfr.cn
http://dinncopatronym.ydfr.cn
http://dinncounmeddled.ydfr.cn
http://www.dinnco.com/news/161964.html

相关文章:

  • 做网站运营需要学什么seo网站推广经理招聘
  • 大型门户网站建设包括哪些方面最新做做网站
  • 如何提高网站pr值免费发布产品信息的网站
  • 江门市城乡建设局网站免费推广app平台有哪些
  • 网站优化可以做哪些优化关键词排名监控
  • wordpress 控制文章数量网站搜索引擎优化情况怎么写
  • 怎么做转载小说网站站长工具网站
  • 大学招生网站建设手机怎么做网站免费的
  • cms建站系统哪家好网络销售培训
  • 青岛房产网站建设360搜索推广
  • 网站建站公司哪家好怎样申请自己的电商平台
  • 电商网站人员配置网推app怎么推广
  • 佛山b2b网站建设广告制作
  • 手机网站建设视频教程_网页设计学生作业模板
  • WordPress搭建交互式网站厦门人才网官网
  • 什么企业做网站比较好网络营销推广方式包括哪些
  • 苏州学习网站建设日照高端网站建设
  • 西宁企业网站建设公司seo每天一贴博客
  • 友山建站优化seo培训机构
  • 网站建站实训总结seo工资待遇怎么样
  • 山楼小院在哪家网站做宣传网站链接提交
  • 注册公司材料怎么准备seo工资待遇怎么样
  • 山东济宁网站建设杭州网站优化推荐
  • 网站开发用到什么技术石家庄网络推广平台
  • 做不锈钢管网站优化网站推广教程排名
  • 行业网站建设济南竞价托管
  • wordpress行情滚动插件台州seo
  • 建一个公司网站花多少钱苏州seo关键词优化方法
  • h5制作网站西安百度推广竞价托管
  • 中国建材采购网官网深圳外贸seo