本文整理汇总了C++中Singleton类的典型用法代码示例。如果您正苦于以下问题:C++ Singleton类的具体用法?C++ Singleton怎么用?C++ Singleton使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Singleton类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ClientThread
DWORD WINAPI Server::ClientThread(LPVOID lpParam) //(insert to DEQUE) use MUTEX
{
Singleton* log = Singleton::Instance();
log->Add("Thread: Client runing");
SOCKET sock = (SOCKET)lpParam; //Get socket
while(f)
{
//recv DATA, create STRUCTURE and (insert to DEQUE)MUTEX
//Send will be in APPLY THREAD
if ( recv(sock,rdata.ch,sizeof(DWORD),0) != -1 ) //Wait data //save data to union
{
Message tmp;
tmp.s = sock;
tmp.data = rdata.i;
WaitForSingleObject(hMutex,INFINITE);
deque_data.push_back(tmp);
ReleaseMutex(hMutex);
}
else
{
break;
}
}
log->Add("Thread: Client stoped");
return 0;
}
示例2: main
int main(void)
{
HANDLE hE = CreateEvent(NULL,false,true,L"{@0001_Start_Program_Event}");
if ( GetLastError() == ERROR_ALREADY_EXISTS )
{ //program running
return 0;
}
Singleton* log = Singleton::Instance();
Server server;
if ( server.Activate() )
{
cout << "ok" << endl;
}
int k = 10;
while (k)
{
system("cls");
log->Show();
system("@pause");
k--;
if (k == 1)
{
server.Deactivate(); //END THREADS
}
}
system("@Pause");
return 0;
}
示例3: main
int main(int argc , char *argv [])
{
Singleton *singletonObj = Singleton ::GetInstance();
cout<<singletonObj->GetTest()<<endl;
return 0;
}
示例4: disconnect
AnalitikaArtikliLista::~AnalitikaArtikliLista()
{
disconnect(sm, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, SLOT(selectionChanged(QModelIndex,QModelIndex)));
disconnect(header, SIGNAL(sectionResized(int, int, int)), this, SLOT(procSectionResized(int, int, int)));
disconnect(header_2, SIGNAL(sectionResized(int, int, int)), this, SLOT(procSectionResizedDetail(int, int, int)));
Singleton *s = Singleton::Instance();
QStringList tempVals = s->saveWidthList(colWidth);
s->Set_Faktura_HeaderState(tempVals);
QStringList tempdetailVals = s->saveWidthList(colDetailWidth);
s->Set_FakturaDetail_HeaderState(tempdetailVals);
delete ui;
delete model;
delete header;
delete model_2;
delete header_2;
delete b;
b = 0;
delete bc;
bc = 0;
delete bd;
bd = 0;
}
示例5: main
int main()
{
Singleton* instance = Singleton::get();
std::cout << instance->showData() << std::endl;
return 0;
}
示例6: setExecutor
void setExecutor(
std::shared_ptr<Exe> executor,
Singleton<std::weak_ptr<Exe>>& sExecutor,
Singleton<RWSpinLock, LockTag>& sExecutorLock) {
RWSpinLock::WriteHolder guard(sExecutorLock.get());
*sExecutor.get() = std::move(executor);
}
示例7: main
int main()
{
Singleton *singleton = Singleton::getInstance();
singleton->singletonOperation();
return 0;
}
示例8: getExecutor
std::shared_ptr<Exe> getExecutor(
Singleton<std::weak_ptr<Exe>>& sExecutor,
Singleton<std::shared_ptr<DefaultExe>>& sDefaultExecutor,
Singleton<RWSpinLock, LockTag>& sExecutorLock) {
std::shared_ptr<Exe> executor;
auto singleton = sExecutor.try_get();
auto lock = sExecutorLock.try_get();
{
RWSpinLock::ReadHolder guard(lock.get());
if ((executor = sExecutor.try_get()->lock())) {
return executor;
}
}
RWSpinLock::WriteHolder guard(lock.get());
executor = singleton->lock();
if (!executor) {
std::weak_ptr<Exe> defaultExecutor = *sDefaultExecutor.try_get().get();
executor = defaultExecutor.lock();
sExecutor.try_get().get()->swap(defaultExecutor);
}
return executor;
}
示例9: main
int main()
{
Singleton *s = Singleton::getInstance();
s->printInfo();
Singleton *s2 = Singleton::getInstance();
s2->printInfo();
Singleton *s3 = Singleton::getInstance();
s3->printInfo();
// Singleton *s4 = new Singleton();
// Singleton s5;
/* 创建线程,在线程里也去调用Singleton::getInstance */
pthread_t thread1ID;
pthread_t thread2ID;
pthread_create(&thread1ID, NULL, start_routine_thread1, NULL);
pthread_create(&thread2ID, NULL, start_routine_thread2, NULL);
sleep(3);
return 0;
}
示例10: thread_routine
void* thread_routine(void* arg)
{
std::cout << pthread_self() << std::endl;
Singleton* pInstance = Singleton::GetInstance();
pInstance->Print();
// 多线程下无法释放内存,否则会导致程序宕掉,最终导致内存泄漏
return NULL;
}
示例11: main
int main(void){
Singleton *instance = Singleton::getInstance();
instance->setValue(35);
cout << instance->getValue() << endl;
Singleton *object = Singleton::getInstance();
cout << object->getValue() << endl;
}
示例12: main
int main() {
Singleton *s = Singleton::getInstance();
s->pulse();
cout << "main: global_ptr is " << GlobalClass::instance()->get_value() << '\n';
foo();
bar();
return 0;
}
示例13:
void Game::_broadcastPacket(PacketContainer* p, bool tcp)
{
Singleton<NetworkManager> *network = NULL;
for (auto it = this->_clients.begin(); it != this->_clients.end(); ++it)
{
network->getInstance()->sendPacket(p->getPacketSerialised(), (*it)->getConnexion(), tcp);
}
}
示例14: setExecutor
void setExecutor(
std::shared_ptr<Exe> executor,
Singleton<std::weak_ptr<Exe>>& sExecutor,
Singleton<RWSpinLock, LockTag>& sExecutorLock) {
auto lock = sExecutorLock.try_get();
RWSpinLock::WriteHolder guard(*lock);
std::weak_ptr<Exe> executor_weak = executor;
sExecutor.try_get().get()->swap(executor_weak);
}
示例15:
void *start_routine_thread2(void *arg)
{
cout<<"this is thread 2 ..."<<endl;
Singleton *s = Singleton::getInstance();
s->printInfo();
return NULL;
}