資料介紹
軟件簡介
MPMCQueue 是一個用C ++ 11編寫的有界多生產者多用戶無鎖隊列。
示例代碼
MPMCQueueq(10); auto t1 = std::thread([&] { int v; q.pop(v); std::cout << "t1 " << v << "\n"; }); auto t2 = std::thread([&] { int v; q.pop(v); std::cout << "t2 " << v << "\n"; }); q.push(1); q.push(2); t1.join(); t2.join();
使用
-
MPMCQueue
(size_t capacity); Constructs a new?
MPMCQueue
?holding items of type?T
?with capacity?capacity
. -
void emplace(Args &&... args);
Enqueue an item using inplace construction. Blocks if queue is full.
-
bool try_emplace(Args &&... args);
Try to enqueue an item using inplace construction. Returns?
true
?on success and?false
?if queue is full. -
bool push(const T &v);
Enqueue an item using copy construction. Blocks if queue is full.
-
template
bool push(P &&v); Enqueue an item using move construction. Participates in overload resolution only if?
std::is_nothrow_constructible
. Blocks if queue is full.::value == true -
bool try_push(const T &v);
Try to enqueue an item using copy construction. Returns?
true
?on success and?false
?if queue is full. -
template
bool try_push(P &&v); Try to enqueue an item using move construction. Participates in overload resolution only if?
std::is_nothrow_constructible
. Returns?::value == true true
?on success and?false
?if queue is full. -
void pop(T &v);
Dequeue an item by copying or moving the item into?
v
. Blocks if queue is empty. -
bool try_pop(T &v);
Try to dequeue an item by copying or moving the item into?
v
. Return?true
?on sucess and?false
?if the queue is empty.
所有操作都是線程安全的,除了構造和析構函數。
實際原理
Enqeue:
- Acquire next write?ticket?from?head.
- Wait for our?turn?(2 * (ticket / capacity)) to write?slot?(ticket % capacity).
- Set?turn = turn + 1?to inform the readers we are done writing.
Dequeue:
- Acquire next read?ticket?from?tail.
- Wait for our?turn?(2 * (ticket / capacity) + 1) to read?slot?(ticket % capacity).
- Set?turn = turn + 1?to inform the writers we are done reading.
參考資料:
- Dave Dice.?PTLQueue : a scalable bounded-capacity MPMC queue.
- Dmitry Vyukov.?Bounded MPMC queue.
- Massimiliano Meneghin et al.?Performance evaluation of inter-thread communication mechanisms on multicore/multithreaded architectures.
- Oleksandr Otenko.?US 8607249 B2: System and method for efficient concurrent queue implementation.
- Paul E. McKenney.?Memory Barriers: a Hardware View for Software Hackers.
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
- 国民技术使用MMU进行多用户场景下的FLASH分区保护V10次下载
- 基于延迟接受的多用户任务卸载策略MUTODA8次下载
- 基于无证书密码体制的多用户秘闻检索方案3次下载
- 多用户多副本数据持有性证明方案0次下载
- 基于自由搜索的多用户检测_任诚0次下载
- 基于物联网的多用户智能电表系统81次下载
- 多用户密码锁的设计117次下载
- 基于遗传算法和小波变换的混合多用户检测17次下载
- 基于DSP的多用户混沌保密通信系统研究5次下载
- 同步短波差分跳频多址系统单用户及多用户检测的性能21次下载
- 下行MIMO通信系统的多用户分集研究14次下载
- 一种多用户多中继MIMO通信系统迭代预编码方案11次下载
- 多用户检测技术在WCDMA中的应用10次下载
- 多用户通信系统9次下载
- 多用户检测技术对CDMA系统的影响研究13次下载
- 晶华微多用户代码烧录器解决方案725次阅读
- 裸机中环形队列与RTOS中消息队列有何区别呢?871次阅读
- RocketMQ生产者为什么需要负载均衡?570次阅读
- 消息队列的发展历史1359次阅读
- RabbitMQ中的路由模型(direct)611次阅读
- 怎么设计实现一个无锁高并发的环形连续内存缓冲队列1557次阅读
- 什么是消息队列?消息队列中间件重要吗?1588次阅读
- SystemVerilog中的队列4336次阅读
- 关于CAS等原子操作介绍 无锁队列的链表实现方法3594次阅读
- 干货:Linux内核中等待队列的四个用法2973次阅读
- 单表多用户模块化智能电表系统的原理及设计2071次阅读
- Linux系统下如何临时或者永久关闭防火墙17759次阅读
- 深度解读通信系统中的CDMA多用户传输仿真技术2300次阅读
- 无线知识充电站:图解多址技术2858次阅读
- 多队列FIFO——支持网络QoS的重要芯片1244次阅读
下載排行
本周
- 1山景DSP芯片AP8248A2數據手冊
- 1.06 MB | 532次下載 | 免費
- 2RK3399完整板原理圖(支持平板,盒子VR)
- 3.28 MB | 339次下載 | 免費
- 3TC358743XBG評估板參考手冊
- 1.36 MB | 330次下載 | 免費
- 4DFM軟件使用教程
- 0.84 MB | 295次下載 | 免費
- 5元宇宙深度解析—未來的未來-風口還是泡沫
- 6.40 MB | 227次下載 | 免費
- 6迪文DGUS開發指南
- 31.67 MB | 194次下載 | 免費
- 7元宇宙底層硬件系列報告
- 13.42 MB | 182次下載 | 免費
- 8FP5207XR-G1中文應用手冊
- 1.09 MB | 178次下載 | 免費
本月
- 1OrCAD10.5下載OrCAD10.5中文版軟件
- 0.00 MB | 234315次下載 | 免費
- 2555集成電路應用800例(新編版)
- 0.00 MB | 33566次下載 | 免費
- 3接口電路圖大全
- 未知 | 30323次下載 | 免費
- 4開關電源設計實例指南
- 未知 | 21549次下載 | 免費
- 5電氣工程師手冊免費下載(新編第二版pdf電子書)
- 0.00 MB | 15349次下載 | 免費
- 6數字電路基礎pdf(下載)
- 未知 | 13750次下載 | 免費
- 7電子制作實例集錦 下載
- 未知 | 8113次下載 | 免費
- 8《LED驅動電路設計》 溫德爾著
- 0.00 MB | 6656次下載 | 免費
總榜
- 1matlab軟件下載入口
- 未知 | 935054次下載 | 免費
- 2protel99se軟件下載(可英文版轉中文版)
- 78.1 MB | 537798次下載 | 免費
- 3MATLAB 7.1 下載 (含軟件介紹)
- 未知 | 420027次下載 | 免費
- 4OrCAD10.5下載OrCAD10.5中文版軟件
- 0.00 MB | 234315次下載 | 免費
- 5Altium DXP2002下載入口
- 未知 | 233046次下載 | 免費
- 6電路仿真軟件multisim 10.0免費下載
- 340992 | 191187次下載 | 免費
- 7十天學會AVR單片機與C語言視頻教程 下載
- 158M | 183279次下載 | 免費
- 8proe5.0野火版下載(中文版免費下載)
- 未知 | 138040次下載 | 免費
評論