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的更多相关文章

随机推荐

  1. JSP之错误信息提示

    MessageResource.properties配置文件: RegisterAction注册: package com.caiduping.action; import javax.servlet ...

  2. php中magic_quotes_gpc对unserialize的影响

    昨天朋友让我帮他解决下他网站的购物车程序的问题,程序用的是PHPCMS,换空间前是好的(刚换的空间),具体问题是提示成功加入购物车后跳转到购物车页面,购物车里为空. 我看了下代码,大致的原理就是将产品 ...

  3. OSPF多区域配置

    1.配置三台路由器IP R1(config)#INTER S1/0 R1(config-if)#IP ADDress 192.1.12.1 255.255.255.0 R1(config-if)#no ...

  4. 利用 Google API 调用谷歌地图 演示1

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. 【学习笔记】【C语言】scanf函数

    1. 简介 这也是在stdio.h中声明的一个函数,因此使用前必须加入#include <stdio.h>.调用scanf函数时,需要传入变量的地址作为参数,scanf函数会等待标准输入设 ...

  6. OpenGL-渲染管线的流程(有图有真相)

    视频教程请关注 http://edu.csdn.net/lecturer/lecturer_detail?lecturer_id=440 学习shader之前必须知道的事情,shader(着色语言)到 ...

  7. (转)手把手教你如何架设VPN

    简介 让远程用户连接Exchange Server的传统解决方案是使用Outlook Web Access.然而,为何不使用虚拟专用网(Virtual Private Network,VPN)让你的远 ...

  8. Linux系统目录分析

    Linux系统目录分析 /bin :系统指令目录(如ls.cp.mv等指令) /dev :系统设备目录 /home :系统用户的家,每一个系统用户都在此目录下有一个自己的家,每次登录时,系统都会自动登 ...

  9. Codevs 1231 最优布线问题

    题目描述 Description 学校需要将n台计算机连接起来,不同的2台计算机之间的连接费用可能是不同的.为了节省费用,我们考虑采用间接数据传输结束,就是一台计算机可以间接地通过其他计算机实现和另外 ...

  10. el表达式获取cookie

    ${cookie.name}将获得对应cookie的对象,比如我们用jsp将一段cookie发送给客户端. Cookie cookie = new Cookie("username" ...