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

百度网站流量统计wordpress分类目录不显示导航标签

百度网站流量统计,wordpress分类目录不显示导航标签,怎么给网站做懒加载,网络课程网站建设线程的创建 用std::thread创建线程非常简单#xff0c;只需要提供线程函数或者线程对象即可#xff0c;并可以同时指定线程函数的参数。下面是创建线程的示例#xff1a; #include thread #include iostream using namespace std;void func() {cout 只需要提供线程函数或者线程对象即可并可以同时指定线程函数的参数。下面是创建线程的示例 #include thread #include iostream using namespace std;void func() {cout thread run.... endl; }/// g thread.cpp -lpthread int main() {std::thread t(func);t.join();cout main over... endl;return 0; } 在上例中函数func将会运行于线程对象t中join函数将会阻塞直到线程函数执行结束如果线程函数有返回值返回值将被忽略。 如果不希望线程被阻塞执行可以调用线程的detach方法将线程和线程对象分离。比如下面的例子 #include thread #include iostream #include string.h using namespace std;void func() {cout thread run.... endl; }/// g thread.cpp -lpthread int main() {std::thread t(func);t.detach();///做其他事情cout main over... endl;while(1){if(getchar()){break;}}return 0; } 通过detach线程就和线程对象分离了让线程作为后台线程去执行当前线程也不会阻塞了。但需要注意的是detach之后就无法再和线程发生联系了比如detach之后就不能再通过join来等待 线程执行完成线程何时执行完成我们也无法控制了。 线程还可以接收任意个数的参数 #include thread #include iostream #include string.h #include string using namespace std;void func(int i, double db, const string str) {cout i endl;cout db endl;cout str endl; }/// g thread.cpp -lpthread int main() {std::thread t(func, 1, 2, test);t.detach();getchar();return 0; } 上面的例子将会输出 1 2 test 使用这种方法创建线程很方便但需要注意的是std::thread出了作用域之后将会析构这时如果线程函数还没有执行完就会发生错误因此需要保证线程函数的生命周期在线程变量std::thread的生命周期之内。 线程不能复制但可以移动例如 #include thread #include iostream #include string.h #include string using namespace std;void func() {cout 111111111111 endl; }/// g thread.cpp -lpthread int main() {std::thread t(func);std::thread t1(std::move(t));t1.join();getchar();return 0; } 线程被移动之后线程对象t将不在不代表任何线程了。另外还可以通过std::bind或lambda表达式来创建线程代码如下 #include thread #include iostream #include string.h #include string #include functional using namespace std;void func(int a, double db) {cout a \t db endl; }/// g thread.cpp -lpthread int main() {std::thread t1(std::bind(func, 1, 2));std::thread t2([](int a, double db){ cout a \t db endl;}, 5, 6);t1.join();t2.join();getchar();return 0; } 需要注意的是线程对象的生命周期比如下面的代码 #include thread #include iostream #include string.h #include string #include functional using namespace std;void func(int a, double db) {cout a \t db endl; }/// g thread.cpp -lpthread int main() {std::thread t1(func, 1, 2);///join函数注释了会有异常发生///t1.join();return 0; } 上面的代码运行可能会抛出异常因为线程对象可能先于线程函数结束应该保证线程对象的生命周期在线程函数执完时仍然存在。可以通过join方法来阻塞等待线程函数执行完或者通过detach方法让线程在后台执行。 线程的基本用法 获取当前信息 线程可以通过当前线程的ID还可以获取CPU核心数量例如 #include thread #include iostream #include string.h #include string #include functional using namespace std;void func() { }/// g thread.cpp -lpthread int main() {std::thread t1(func);cout t1.get_id() endl;cout std::thread::hardware_concurrency() endl;t1.join();return 0; } 线程休眠 可以使当前线程休眠一定时间代码如下 #include thread #include iostream #include string.h #include string #include functional using namespace std;void func() {std::this_thread::sleep_for(std::chrono::seconds(3));cout time out endl; }/// g thread.cpp -lpthread int main() {std::thread t1(func);t1.join();return 0; } 在上面的例子中线程将会休眠3秒3秒之后将打印time out。
http://www.hkea.cn/news/14527978/

相关文章:

  • 做家教网站如何招生影院禁止18岁以下观众观影
  • 如何做网站弹窗广告建设门户网站价格
  • 哪个网站做欧洲旅游攻略好宽带推广方案
  • 天津市哪里有做网站广告的临沂专门做网站的
  • 网站收录不增加大连网页制作培训
  • 济南电商培训基地快照首页排名优化服务
  • 大朗网站建设公司网络规划设计师考试资料百度云
  • 辽宁网站建设企业wordpress 百度 插件怎么用
  • 天津网站建设业务wordpress视频加密
  • wordpress影视主题模板免费下载seo快速建站
  • 做个简单网站大概多少钱平面设计月薪大概多少
  • 网站程序制作软件网络营销推广方案pdf
  • 公司网站 数据库中国建筑师室内设计网
  • 智慧团建官方网站电脑版外包开发app需要多少钱
  • 子洲网站建设制作优化关键词排名外包
  • 网站设计与开发专家wordpress 上一篇下一篇 文章的图片
  • 广州网站推广电话做网站公司什么条件
  • 制作广告网站的步骤推广网站怎么做
  • 没有公司可以做网站吗网页设计类型与风格
  • 零食网站制作的建设大纲页面设计原型图
  • 深圳外贸网站优化哪家好企业网站做app
  • 公司建设网站申请报告范文手机网站快速建设
  • wordpress5.0正式发布网站文章在哪发布做seo
  • 自己做网站哪种好做提高网站权重的作用
  • 网站建设与运营答案广州海珠区租房子一般多少钱
  • 泰州网站开发做网站能用自己电脑吗
  • 自己怎么做网上注册免费的网站某网站开发项目进度表
  • 长沙市网站开发网站开发工程师职业
  • 重庆长寿网站设计公司推荐网络营销存在的问题及解决对策
  • 做维修那个网站发布信息好网站建设的介绍