摘要: #include<iostream> #include<mutex> #include<thread> using namespace std; template<class T> class Shared_Ptr{ public: Shared_Ptr(T* ptr = nullptr) :_pP 阅读全文
posted @ 2021-08-25 16:08 wsl-hitsz 阅读(60) 评论(0) 推荐(0) 编辑
摘要: 清楚认识到读写锁分为共享锁(读锁)和独占锁(写锁),可能通过设置标志位记录读锁调用的次数结合互斥锁实现共享锁。但需要注意的是,以下的实现在多个写锁被阻塞时非常消耗计算机资源。因为线程阻塞在写锁中而没有被投入睡眠,导致轮询策略。避免轮询可通过互斥锁+条件变量实现读写锁,具体实现见上一篇博文。 以下是代 阅读全文
posted @ 2021-08-25 15:59 wsl-hitsz 阅读(204) 评论(0) 推荐(0) 编辑