![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
多线程
文章平均质量分 52
CodingLife99
这个作者很懒,什么都没留下…
展开
-
现代C++中thread和async的简单对比
C++11中引入了thread类,使用它可以很方便的创建线程.创建的形式为thread t(函数名, 参数…),执行完此行代码,线程函数就直接运行起来了,不需要单独的启动函数.不过主线程中仍然需要join()来等待子线程运行完毕 此外C++11中还引入了async函数,是一种更高层的异步方式.它可以用std::future类型的变量来接收线程函数运行的结果,并通过get()的方法来获得结果.这样就不必像thread那样提前定义一个全局变量,在线程函数中进行赋值操作. 此外async还可以指定线程创建策略–是原创 2021-04-13 19:59:56 · 992 阅读 · 1 评论 -
单例模式(用判断nullptr和call_once两种方法)
使用判断nullptr #include <thread> #include <iostream> using namespace std; class Singleton { private: Singleton() { } static Singleton * m_singleton;//C++类中不可以定义自己类的对象,但是可以定义自己类的指针和引用. public: static Singleton * getIn原创 2021-04-10 21:11:40 · 211 阅读 · 1 评论 -
查看一个多线程程序
top -H是以多线程的方式来展示 pstack pid能够展示某个进程的堆栈 #include<stdio.h>//perror在此.h #include<iostream> #include<pthread.h> #include<unistd.h> using namespace std; void * routine(void *arg) { int i = int(*(int *)arg); cout << "th.原创 2020-11-17 23:40:51 · 120 阅读 · 0 评论