代码拉取完成,页面将自动刷新
#include "../inc/singleton_.h"
#include <thread>
shared_ptr<Singleton_> Singleton_::_inst = nullptr;
mutex Singleton_::_mutex;
void test_single()
{
shared_ptr<Singleton_> inst1 = Singleton_::getinstance();
cout << "inst1 get ptr is " << inst1.get() << endl;
shared_ptr<Singleton_> inst2 = Singleton_::getinstance();
cout << "inst2 get ptr is " << inst2.get() << endl;
}
void thread_func(int i)
{
cout << "this is thread " << i << endl;
shared_ptr<Singleton_> inst = Singleton_::getinstance();
cout << "inst ptr is " << inst.get() << endl;
}
void test_thread_single()
{
for (int i = 0; i < 3; i++)
{
thread tid(thread_func, i + 1);
tid.join();
}
cout << "main thread exit " << endl;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。