c++ freelockquque
http://www.boost.org/doc/libs/1_56_0/doc/html/boost/lockfree/queue.html Class template queue boost::lockfree::queue
Synopsis // In header: <boost/lockfree/queue.hpp> template<typename T, ... Options>
class queue {
public:
// types
typedef T value_type;
typedef implementation_defined::allocator allocator;
typedef implementation_defined::size_type size_type; // construct/copy/destruct
queue(void);
template<typename U>
explicit queue(typename node_allocator::template rebind< U >::other const &);
explicit queue(allocator const &);
explicit queue(size_type);
template<typename U>
queue(size_type,
typename node_allocator::template rebind< U >::other const &);
~queue(void); // public member functions
bool is_lock_free(void) const;
void reserve(size_type);
void reserve_unsafe(size_type);
bool empty(void);
bool push(T const &);
bool bounded_push(T const &);
bool unsynchronized_push(T const &);
bool pop(T &);
template<typename U> bool pop(U &);
bool unsynchronized_pop(T &);
template<typename U> bool unsynchronized_pop(U &);
template<typename Functor> bool consume_one(Functor &);
template<typename Functor> bool consume_one(Functor const &);
template<typename Functor> size_t consume_all(Functor &);
template<typename Functor> size_t consume_all(Functor const &);
}; Description The queue class provides a multi-writer/multi-reader queue, pushing and popping is lock-free, construction/destruction has to be synchronized. It uses a freelist for memory management, freed nodes are pushed to the freelist and not returned to the OS before the queue is destroyed. Policies: boost::lockfree::fixed_sized, defaults to boost::lockfree::fixed_sized<false>
Can be used to completely disable dynamic memory allocations during push in order to ensure lockfree behavior.
If the data structure is configured as fixed-sized, the internal nodes are stored inside an array and they are addressed by array indexing. This limits the possible size of the queue to the number of elements that can be addressed by the index type (usually **-), but on platforms that lack double-width compare-and-exchange instructions, this is the best way to achieve lock-freedom. boost::lockfree::capacity, optional
If this template argument is passed to the options, the size of the queue is set at compile-time.
It this option implies fixed_sized<true> boost::lockfree::allocator, defaults to boost::lockfree::allocator<std::allocator<void>>
Specifies the allocator that is used for the internal freelist Requirements: T must have a copy constructor T must have a trivial assignment operator T must have a trivial destructor queue public construct/copy/destruct queue(void); Construct queue. template<typename U>
explicit queue(typename node_allocator::template rebind< U >::other const & alloc); explicit queue(allocator const & alloc); explicit queue(size_type n); Construct queue, allocate n nodes for the freelist. template<typename U>
queue(size_type n,
typename node_allocator::template rebind< U >::other const & alloc); ~queue(void); Destroys queue, free all nodes from freelist. queue public member functions bool is_lock_free(void) const; [Warning] Warning It only checks, if the queue head and tail nodes and the freelist can be modified in a lock-free manner. On most platforms, the whole implementation is lock-free, if this is true. Using c++0x-style atomics, there is no possibility to provide a completely accurate implementation, because one would need to test every internal node, which is impossible if further nodes will be allocated from the operating system. Returns: true, if implementation is lock-free. void reserve(size_type n); Allocate n nodes for freelist [Note] Note thread-safe, may block if memory allocator blocks Requires: only valid if no capacity<> argument given void reserve_unsafe(size_type n); Allocate n nodes for freelist [Note] Note not thread-safe, may block if memory allocator blocks Requires: only valid if no capacity<> argument given bool empty(void); Check if the queue is empty [Note] Note The result is only accurate, if no other thread modifies the queue. Therefore it is rarely practical to use this value in program logic. Returns: true, if the queue is empty, false otherwise bool push(T const & t); Pushes object t to the queue. [Note] Note Thread-safe. If internal memory pool is exhausted and the memory pool is not fixed-sized, a new node will be allocated from the OS. This may not be lock-free. Postconditions: object will be pushed to the queue, if internal node can be allocated Returns: true, if the push operation is successful. bool bounded_push(T const & t); Pushes object t to the queue. [Note] Note Thread-safe and non-blocking. If internal memory pool is exhausted, operation will fail Postconditions: object will be pushed to the queue, if internal node can be allocated Returns: true, if the push operation is successful. Throws:
if memory allocator throws bool unsynchronized_push(T const & t); Pushes object t to the queue. [Note] Note Not Thread-safe. If internal memory pool is exhausted and the memory pool is not fixed-sized, a new node will be allocated from the OS. This may not be lock-free. Postconditions: object will be pushed to the queue, if internal node can be allocated Returns: true, if the push operation is successful. Throws:
if memory allocator throws bool pop(T & ret); Pops object from queue. [Note] Note Thread-safe and non-blocking Postconditions: if pop operation is successful, object will be copied to ret. Returns: true, if the pop operation is successful, false if queue was empty. template<typename U> bool pop(U & ret); Pops object from queue. [Note] Note Thread-safe and non-blocking Requires: type U must be constructible by T and copyable, or T must be convertible to U Postconditions: if pop operation is successful, object will be copied to ret. Returns: true, if the pop operation is successful, false if queue was empty. bool unsynchronized_pop(T & ret); Pops object from queue. [Note] Note Not thread-safe, but non-blocking Postconditions: if pop operation is successful, object will be copied to ret. Returns: true, if the pop operation is successful, false if queue was empty. template<typename U> bool unsynchronized_pop(U & ret); Pops object from queue. [Note] Note Not thread-safe, but non-blocking Requires: type U must be constructible by T and copyable, or T must be convertible to U Postconditions: if pop operation is successful, object will be copied to ret. Returns: true, if the pop operation is successful, false if queue was empty. template<typename Functor> bool consume_one(Functor & f); consumes one element via a functor pops one element from the queue and applies the functor on this object [Note] Note Thread-safe and non-blocking, if functor is thread-safe and non-blocking Returns: true, if one element was consumed template<typename Functor> bool consume_one(Functor const & f); consumes one element via a functor pops one element from the queue and applies the functor on this object [Note] Note Thread-safe and non-blocking, if functor is thread-safe and non-blocking Returns: true, if one element was consumed template<typename Functor> size_t consume_all(Functor & f); consumes all elements via a functor sequentially pops all elements from the queue and applies the functor on each object [Note] Note Thread-safe and non-blocking, if functor is thread-safe and non-blocking Returns: number of elements that are consumed template<typename Functor> size_t consume_all(Functor const & f); consumes all elements via a functor sequentially pops all elements from the queue and applies the functor on each object [Note] Note Thread-safe and non-blocking, if functor is thread-safe and non-blocking Returns: number of elements that are consumed
c++ freelockquque的更多相关文章
随机推荐
- onclick跳转
☆如果是本页显示可以直接用location,方法如下: ①onclick="javascript:window.location.href='URL'" ②onclick=&quo ...
- 第三方框架、AFN、ASI、SDWebImage
AFN 一.2大管理对象1.AFHTTPRequestOperationManager* 对NSURLConnection的封装 2.AFHTTPSessionManager* 对NSURLSessi ...
- eclipse安装tomcate插件步骤
今天在网上看了很多关于eclipse需要安装tomcat的文章,小编也没有指责的意思,只是想说为什么有那么多雷同且不正确的搭建过程,真是ctrl+c, ctrl+v玩多了吧,不知道流程有的是错误的,不 ...
- ionic2 页面加载时图片添加的问题
使用ionic2创建项目时,在app文件夹下有图片目录img 在home中引用图片,但是不论是用ng-src或者是src,代码如下: <ion-list> <ion-slides c ...
- startup.bat闪退---tomcat环境变量配置中遇到的问题
常用的方法: 1.在已解压的tomcat的bin文件夹下找到startup.bat,右击->编辑.在文件头加入下面两行: SET JAVA_HOME=D:\Java\jdk1.6.0_10 ...
- Java线程面试题 Top 50(转载)
原文链接:http://www.importnew.com/12773.html 本文由 ImportNew - 李 广 翻译自 javarevisited.欢迎加入Java小组.转载请参见文章末尾的 ...
- 杭电ACM2092--整数解
杭电ACM2092--整数解 分析 http://acm.hdu.edu.cn/showproblem.php?pid=2092 一个YES,一个Yes.试了10几次..我也是无语了..哪里都不 ...
- 《postfix邮件服务下mailq、postmap、postqueue 、 postsuper等用法》
1.Mailq 功能说明:显示待寄邮件的清单. 语 法:mailq [-q] 补充说明:mailq可列出待寄邮件的清单,包括邮件ID,邮件大小,邮件保存时间,寄信人,收信人,以及邮件无法寄出的原因,提 ...
- 将json转为复杂url参数
//json转url参数 var parseParam = function(param, key) { var paramStr = ""; if (param instance ...
- SQL 面试题(一)
问题来自于CSDN问答,练练SQL吧. 测试数据SQL代码: if OBJECT_ID('td_ls_2') is not null drop table td_ls_2 go if OBJECT_I ...