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

雕刻业务网站怎么做企业qq官网

雕刻业务网站怎么做,企业qq官网,化妆品网站建设思路,哔哩哔哩做视频网站本文章记录c创建线程#xff0c;启动线程和结束线程的代码。 需要注意#xff0c;编译时需要添加-lpthread依赖。 代码#xff1a; ThreadTest.h #ifndef TEST_THREAD_TEST_H #define TEST_THREAD_TEST_H#include thread #include mutexclass ThreadTes…本文章记录c创建线程启动线程和结束线程的代码。 需要注意编译时需要添加-lpthread依赖。 代码 ThreadTest.h #ifndef TEST_THREAD_TEST_H #define TEST_THREAD_TEST_H#include thread #include mutexclass ThreadTest {public:void start();void stop();void threadLoop(int a);volatile bool started false;private:std::thread *mThread;std::mutex mMutex; };static void threadRun(ThreadTest* threadTest);#endif // TEST_THREAD_TEST_HThreadTest.cpp #include ThreadTest.h #include iostream// thread entrance. static void threadRun(ThreadTest* threadTest){printf(thread start!\n);int a 0;while (threadTest-started){a;threadTest-threadLoop(a);std::this_thread::sleep_for(std::chrono::milliseconds(1000));}printf(threadRun method exit!\n); };// start thread. void ThreadTest::start(){mMutex.lock();if(started){mMutex.unlock();return;}started true;printf(thread starting!\n);mThread new std::thread(threadRun, this);printf(thread started!\n);mMutex.unlock(); };// stop thread. void ThreadTest::stop(){mMutex.lock();if(!started) {mMutex.unlock();return;}if(started mThread ! nullptr mThread-joinable()) {started false;mThread-join();}printf(thread stopped!\n);mMutex.unlock(); };// run in thread. void ThreadTest::threadLoop(int a){printf(threadLoop, a:%d!\n, a); }; Test.cpp #include ThreadTest.h #include iostream// thread entrance. static void threadRun(ThreadTest* threadTest){printf(thread method called!\n);int a 0;while (threadTest-started){a;threadTest-threadLoop(a);std::this_thread::sleep_for(std::chrono::milliseconds(1000));}printf(threadRun method exit!\n); };// start thread. void ThreadTest::start(){mMutex.lock();if(started){mMutex.unlock();return;}started true;printf(thread starting!\n);mThread new std::thread(threadRun, this);printf(thread started!\n);mMutex.unlock(); };// stop thread. void ThreadTest::stop(){mMutex.lock();if(!started) {mMutex.unlock();return;}if(started mThread ! nullptr mThread-joinable()) {started false;mThread-join();}printf(thread stopped!\n);mMutex.unlock(); };// run in thread. void ThreadTest::threadLoop(int a){printf(threadLoop, a:%d!\n, a); }; 执行 导入IDE执行或用g g -o test Test.cpp -I ThreadTest.h ThreadTest.cpp -lpthread ./test输出 hello world! thread starting! thread started! thread method called! threadLoop, a:1! threadLoop, a:2! threadLoop, a:3! threadRun method exit! thread stopped! ----------------- thread starting! thread method called! threadLoop, a:1! thread started! threadLoop, a:2! threadLoop, a:3! threadRun method exit! thread stopped! thread starting! thread method called! threadLoop, a:1! thread started! threadRun method exit! thread stopped! thread starting! thread started! thread method called! threadRun method exit! thread stopped! thread starting! thread method called! threadLoop, a:1! thread started! threadRun method exit! thread stopped! thread starting! thread started! thread method called! threadRun method exit! thread stopped! thread starting! thread method called! threadLoop, a:1! thread started! threadRun method exit! thread stopped! hello world end!
http://www.w-s-a.com/news/47131/

相关文章:

  • 新华书店的做的数字阅读网站wordpress编辑器格式
  • jq做6个网站做什么好广西临桂建设局网站
  • 网站新闻图片尺寸南京网站设计公司
  • 重庆seo建站网站服务器 安全
  • 咸宁做网站的公司桂林网站建设兼职
  • 教做网站网站开发行业分析
  • 忻州网站建设培训友情链接交换形式有哪些
  • 佛山做外贸网站渠道外贸常用网站
  • 文章收录网站网站及新媒体建设办法
  • 招聘网站排行榜2021找建网站公司
  • 网站建设制作宝塔面板活动宣传推广的形式有哪些
  • 掉关键词网站敏捷软件开发流程
  • 微信小程序格泰网站建设新闻采编与制作专业简历
  • 电子商城建设网站海伦网站建设
  • 南充能够建设网站的公司有专门做设计的一个网站
  • 免费域名申请个人网站阿里巴巴运营的工作内容
  • 怎么建自己的手机网站保定电子商务网站建设
  • 系部网站建设中期检查表创建网站的公司
  • 西宁网站建设优化重庆企业的网站建设
  • 贝壳企业网站管理系统徽与章网站建设宗旨
  • 郑州网站模板动漫设计与制作设计课程
  • 在线制作网站的工具岳阳网站设计改版
  • 网站建设需要汇报哪些内容前端开发的工作内容
  • 无锡阿凡达网站建设美团app开发公司
  • 个性化企业网站制作公司深圳高端网站定制公
  • 专业深圳网站定制开发企业网站开发 流程
  • 网站建设推广的软文php网站平台
  • 如何做代刷网站长外贸网站个性设计
  • 合同网站开发 设计 后期维护如何搭建海外网络
  • 提供网站建设服务优化大师哪个好