单例模式

有没有会写单例模式的大佬  能不能帮我看看我的代码错误是什么情况  我卡住了……😭😭😭
全部评论
你的代码喃?😂
点赞 回复
分享
发布于 2019-07-16 18:16
所以你代码呢
点赞 回复
分享
发布于 2019-07-16 17:38
乐元素
校招火热招聘中
官网直投
代码呢
点赞 回复
分享
发布于 2019-07-16 17:38
代码阻塞了发不出来了
点赞 回复
分享
发布于 2019-07-16 18:01
所以你的代码咩?
点赞 回复
分享
发布于 2019-07-16 18:05
24行 和 30行都有问题 我真的不会了😭😭😭 求大佬们帮帮忙
点赞 回复
分享
发布于 2019-07-17 09:33
#include<iostream> #include<pthread.h> using namespace std; class Single { public:  static pthread_mutex_t mtx;  static Single* get_Single()  {   if(p==NULL)   {    pthread_mutex_lock(&mtx);    if(p==NULL)    {     p=new Single;    }    pthread_mutex_unlock(&mtx);   }   return p;  } private:  static Single* volatile p;  Single()  {  } }; pthread_mutex_t Single ::mtx=PTHREAD_MUTEX_INITIALIZER; Single* Single::p=NULL; void* func1(void* arg) {  while(1)  {   Single* tmp1=Single::get_Single();   cout<<"tmp1  "<<tmp1<<endl;   sleep(1000);  } } void* func2(void* arg) {  while(1)  {   Single* tmp2=Single::get_Single();   cout<<"tmp2  "<<tmp2<<endl;   sleep(1000);  } } int main() {  pthread_t pt1;  pthread_t pt2;  int ret1=pthread_create(&pt1,0,func1,0);  if(ret1!=0)  {   cout<<"ERROR!!!"<<endl;  }  int ret2=pthread_create(&pt2,0,func2,0);  if(ret2!=0)  {   cout<<"ERROR!!!"<<endl;  }  pthread_join(pt1,0);  pthread_join(pt2,0);  return 0; }
点赞 回复
分享
发布于 2019-07-18 10:39

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务