当前位置:网站首页>线程(下):读写者模型\环形队列\线程池
线程(下):读写者模型\环形队列\线程池
2022-08-10 04:26:00 【RNGWGzZs】

"不曾回顾的往事,是那苦笑的释然"
(一)读写者问题;
本篇只简单提一提读写者问题。
(1)什么是读写锁?

①初始化+销毁
#include <pthread.h>
int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
int pthread_rwlock_init(pthread_rwlock_t *restrict rwlock,
const pthread_rwlockattr_t *restrict attr);
②加锁+解锁
int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
只需要注意的是,读写锁与角色强关联。是读者角色就用读者锁,反之则用写者锁。
(2)优先原则
在多线程的情况下:
不管是有人在读的时候,让下一个读者不再进入读取,反之让写者进入临界区 写入---写者优先
还是反之 让写者不再进入,让读者继续读取------读者优先。
本质上 都是由具体的场景来决定谁先谁后的问题。
(二)基于POSIX信号的环形队列

模拟实现生产 消费
框架;

P\V操作;

Push / Pop


(三)线程池
线程池适用于:
需要大量线程完成,且任务时间短
性能苛刻的应有.....

让任务 push进 任务列表,再由线程按序 从任务列表中读取
①框架;


push任务;(这里的任务一定要给处理方案!)
批量化完成任务 
本篇也就只有这么多了。
感谢你的阅读
祝你好运~

边栏推荐
猜你喜欢
随机推荐
JavsSE => 多态
RadiAnt DICOM Viewer 2022.1 Crack
Using the DatePicker date control, Prop being mutated: "placement" error occurs
使用 DatePicker 日期控件,发生 Prop being mutated: “placement“ 报错问题
万字总结:分布式系统的38个知识点
Ueditor editor arbitrary file upload vulnerability
How Current Probes Set Oscilloscope Parameters
最新开源的面试笔记,天花板级别!
虚假新闻检测论文阅读(八):Assessing Arabic Weblog Credibility via Deep Co-learning
社区分享|货拉拉通过JumpServer纳管大规模云上资产
What is the relationship between legal representative and shareholders?
[crit] 23856#0: *101796511 stat()
cmake
长沙:借网红的风,铺长红的路
[Web3 Series Development Tutorial - Create Your First NFT (7)] Create an NFT DApp and assign attributes to your NFT, such as pictures
2022年R2移动式压力容器充装考试题库模拟考试平台操作
ZZULIOJ:1014: 求三角形的面积
ZZULIOJ:1018: 奇数偶数
itoa和aoti函数的自我实现
webrtc学习--webrtc桌面采集









