2022年2月23日
摘要: // // 调用std::future::get时,异步任务会堵塞,直至任务结束。 // std::future对象析构时,异步任务也会堵塞,直至任务结束。 // 如果没有保存std::async的返回值,相当于返回的std::future对象立即析构,此时的异步与同步没有区别。 // void T 阅读全文
posted @ 2022-02-23 08:32 朱迎春 阅读(480) 评论(0) 推荐(0) 编辑
摘要: // // thread对象一定要join,否则Debug会报错:"abort() has been called",Release不报错 // void Test1() { std::cout << "\n Test1 \n"; int res; thread t([&res] (int x) { 阅读全文
posted @ 2022-02-23 08:12 朱迎春 阅读(205) 评论(0) 推荐(0) 编辑
摘要: 多线程操作std::queue的例子: // // std::queue 必须使用 lock 保护,去掉lock_guard后会crash // void Test() { std::cout << "\n Test \n"; mutex mtx; queue<int> numQueue; bool 阅读全文
posted @ 2022-02-23 08:01 朱迎春 阅读(616) 评论(0) 推荐(0) 编辑