首页 > 编程语言 > 详细

C++试题汇总

时间:2019-08-28 23:16:36      阅读:73      评论:0      收藏:0      [点我收藏+]

 

3,手写strcpy,memcpy,memmove函数;

 

2,线程同步几种方式:

互斥锁,信号量,临界区

 

1,实现一个vector,是1.5还是2倍?各有什么优缺点:

(1)1.5倍优势:可以重用之前分配但是释放的内存;

(2)2倍劣势:每次申请的内存都不可以重用;

 

0,线程安全的单例模式

class Singleton{
    private:
        static pthread_mutex_t mtx;
        static Singleton* instance;
        Singleton(){}
        ~Singleton(){}
    public:
        static Singleton* getInstance(){
            if(instance == NULL){
                pthread_mutex_lock(mtx);
                if(instance == NULL){
                    instance = new Singleton();
                }
                pthread_mutex_unlock(mtx);
            }
            return instance;
        }
};

pthread_mutex_t Singleton::mtx = PTHREAD_MUTEX_INITIALIZER;
Singleton Singleton::instance = NULL;

 

C++试题汇总

原文:https://www.cnblogs.com/hujianglang/p/11427039.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!