FastFlow  SVN-r182-Aug-14-2014
A high-level, lock-less, parallel programming (shared-memory) and distributed programming (distributed-memory) framework for multi-cores and many-cores systems
 All Classes Namespaces Files Functions Variables Typedefs Groups Pages
Classes | Namespaces
ubuffer.hpp File Reference

This file contains the definition of the unbounded SWSR circular buffer used in FastFlow. More...

#include <assert.h>
#include <cassert>
#include <new>
#include <ff/dynqueue.hpp>
#include <ff/buffer.hpp>
#include <ff/spin-lock.hpp>
#include <ff/atomic/atomic.h>
+ Include dependency graph for ubuffer.hpp:
+ This graph shows which files directly or indirectly include this file:

Classes

class  ff::uSWSR_Ptr_Buffer
 Unbounded Single-Writer/Single-Reader buffer (FastFlow unbound channel) More...
 

Namespaces

 ff
 The principal namespace for the FastFlow library.
 

Detailed Description

This file contains the definition of the unbounded SWSR circular buffer used in FastFlow.

Single-Writer/Single-Reader (SWSR) lock-free (wait-free) unbounded FIFO queue. No lock is needed around pop and push methods!!

The key idea underneath the implementation is quite simple: the unbounded queue is based on a pool of wait-free SWSR circular buffers (see buffer.hpp). The pool of buffers automatically grows and shrinks on demand. The implementation of the pool of buffers carefully try to minimize the impact of dynamic memory allocation/deallocation by using caching strategies.

More information about the uSWSR_Ptr_Buffer implementation and correctness proof can be found in:

M. Aldinucci, M. Danelutto, P. Kilpatrick, M. Meneghin, and M. Torquati, "An Efficient Unbounded Lock-Free Queue for Multi-core Systems," in Proc. of 18th Intl. Euro-Par 2012 Parallel Processing, Rhodes Island, Greece, 2012, pp. 662-673. doi:10.1007/978-3-642-32820-6_65

IMPORTANT:

This implementation has been optimized for 1 producer and 1 consumer. If you need to use more producers and/or more consumers you have several possibilities (top-down order):

  1. to use an high level construct like the farm skeleton and compositions of multiple farms (in other words, use FastFlow ;-) ).
  2. to use one of the implementations in the MPMCqueues.hpp file
  3. to use the SWSR_Ptr_Buffer but with the mp_push and the mc_pop methods both protected by (spin-)locks in order to protect the internal data structures.