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

dw软件做二级连接网站重庆seo多少钱

dw软件做二级连接网站,重庆seo多少钱,微信答题抽奖小程序制作,网站运营每天做啥工作文章目录 九、多线程2. 线程的控制 未完待续 九、多线程 2. 线程的控制 主线程退出 等同于 进程退出 等同于 所有线程都退出。为了避免主线程退出#xff0c;但是新线程并没有执行完自己的任务的问题#xff0c;主线程同样要跟进程一样等待新线程返回。 pthread_join 函数… 文章目录 九、多线程2. 线程的控制 未完待续 九、多线程 2. 线程的控制 主线程退出 等同于 进程退出 等同于 所有线程都退出。为了避免主线程退出但是新线程并没有执行完自己的任务的问题主线程同样要跟进程一样等待新线程返回。 pthread_join 函数则可以等待新线程返回。 Makefile test_thread: testThread.ccg -o $ $^ -stdc11 -lpthread .PHONY: clean clean:rm -f test_threadtestThread.cc #include iostream #include pthread.h #include unistd.h using namespace std;// 新线程 void* newpthreadrun(void* arg) {int cnt 5;while (cnt--){cout I am newpthreadrun thread endl;sleep(1);} }int main() {pthread_t tid;pthread_create(tid, nullptr, newpthreadrun, nullptr);// 主线程pthread_join(tid, nullptr);cout I am main thread endl;sleep(5);return 0; }多线程中任何一个线程出现异常都会导致整个进程退出 ---- 多线程代码往往健壮性不好。 不能用 exit() 来退出线程因为 exit() 是退出进程的可以使用 pthread_exit() 来退出线程也可以在主线程中使用 pthread_cancel() 来取消新线程线程新线程会返回 -1。 我们来创建一个多线程 Makefile test_thread: testThread.ccg -o $ $^ -stdc11 -lpthread .PHONY: clean clean:rm -f test_threadtestThread.cc #include iostream #include string #include pthread.h #include unistd.h #include vector #include cstdio #include cstdlib using namespace std;const int threadnum 5;// 加法任务 class Task { public:Task(int x, int y):datax(x),datay(y){}int Excute(){return datax datay;}~Task() {} private:int datax;int datay; };// 线程数据 class ThreadData { public:ThreadData(int x, int y, const string threadname):t(x, y),threadname(threadname){}string Threadname(){return threadname;}int run(){return t.Excute();}~ThreadData() {} private:string threadname;Task t; };// 执行任务后的结果 class Result { public:Result() {}void SetResult(int result, const string threadname){_result result;_threadname threadname;}void Print(){cout _threadname run result: _result endl;}~Result() {} private:int _result;string _threadname; };// 线程执行任务 void* handlerTask(void* args) {ThreadData* td static_castThreadData*(args);string name td-Threadname();Result* res new Result();int result td-run();res-SetResult(result, name);return res; }int main() {// 创建线程并分配任务vectorpthread_t threads;for (int i 0; i threadnum; i){char threadname[64];snprintf(threadname, 64, Thread-%d, i 1);ThreadData* td new ThreadData(10, 20, threadname);pthread_t tid;pthread_create(tid, nullptr, handlerTask, td);threads.push_back(tid);}// 等待线程执行完毕并获取结果vectorResult* result_set;void* ret nullptr;for (auto tid : threads){pthread_join(tid, ret);result_set.push_back((Result*)(ret));}// 打印结果for (auto res : result_set){res-Print();delete res;}return 0; }执行结果 未完待续
http://www.yayakq.cn/news/5160/

相关文章:

  • 有哪几种语言做的网站内部网站建设要求
  • wordpress 调用分类整站seo优化推广
  • 使用的电脑做网站的服务器长沙企业网站建立
  • tp5网站文档归档怎么做怎么做网站推广图片
  • 加强门户网站建设的方案深圳公司注册多少钱
  • 做策划的网站推广重庆seo排名公司
  • 厦门学网站设计安徽城乡与建设部网站
  • 宁波网站建设设计公司汕头seo快速排名
  • 淮安网站网站建设关于门户网站建设报告
  • 深圳市seo网站设计哪家好有哪些企业可以做招聘的网站有哪些
  • 深圳成交型网站建设东莞常平网络推广外包
  • 模版破解免费wordpress爱站网seo综合查询
  • 网站本身对网站打开速度有何影响申请了域名怎么做网站
  • 内江如何做百度的网站百度站长论坛
  • 设计类电子书网站对比网页设计网站
  • 怎么上传软件到网站合肥公司网站建设价格
  • 公司logo设计图片免费泉州网站建设方案优化
  • 大学英语精品课程网站建设万方期刊网官网
  • 深圳网站建设自己人网站建设方案书阿里云备案
  • 模板建网站wordpress contactform
  • 网站怎么设置关键词爆款采集推广引流软件
  • 地板网站建设方案优秀设计平台
  • 阿里免费做网站百度官网入口链接
  • 布吉网站建设公司网站顶部设计
  • 网站建站解决方案软文推广模板
  • dede免费网站模板utf8凡科小程序商城
  • 广东省建设注册中心网站网站建设人员叫什么
  • iis8出现在网站首页官方网站想反应问题不弄应该怎么做
  • 网站建设的活动方案哪个网站做外贸假发好
  • 网站怎么做动态主图乐昌门户网站