Zero  0.1.0
Public Member Functions | Public Attributes | List of all members
MarkablePointerChain< NEXT > Struct Template Reference

Atomic Markable Pointer Chain for lock-free list/queue/etc. More...

#include <w_markable_pointer.h>

Public Member Functions

 MarkablePointerChain ()
 
 MarkablePointerChain (const MarkablePointerChain &other)
 
MarkablePointerChainoperator= (const MarkablePointerChain &other)
 

Public Attributes

MarkablePointer< NEXT > next
 

Detailed Description

template<class NEXT>
struct MarkablePointerChain< NEXT >

Atomic Markable Pointer Chain for lock-free list/queue/etc.

Template Parameters
NEXTPointed class

What it is for

Container class like list/queue often needs an object to hold both a value and a pointer to next such object. For example, Chap 9.8 and Chap 10.6 of [HERLIHY] use "Node" class for that purpose. This is required because we need to atomically switch some value and a pointer together in those lock-free algorithm. Otherwise we are risking SEGFAULT when the pointed object gets revoked by other threads.

One way to achieve it is to define a Node class in the container (as in [HERLIHY]), but that means lock-free methods have to allocate and deallocate objects, which is usually expensive and might not be lock-free!

The solution is to have "next" MarkablePointer in the containee class itself. This class is a template for such use and you can either just derive from this class. Yes, it's 8 more bytes, but sometimes we need to pay the price.

See also
http://blog.memsql.com/common-pitfalls-in-writing-lock-free-algorithms/
MarkablePointer

Dependency

This tiny class is completely header-only. To use, just include w_markable_pointer.h.

Constructor & Destructor Documentation

§ MarkablePointerChain() [1/2]

template<class NEXT >
MarkablePointerChain< NEXT >::MarkablePointerChain ( )
inline

§ MarkablePointerChain() [2/2]

template<class NEXT >
MarkablePointerChain< NEXT >::MarkablePointerChain ( const MarkablePointerChain< NEXT > &  other)
inline

Member Function Documentation

§ operator=()

template<class NEXT >
MarkablePointerChain& MarkablePointerChain< NEXT >::operator= ( const MarkablePointerChain< NEXT > &  other)
inline

Member Data Documentation

§ next

template<class NEXT >
MarkablePointer<NEXT> MarkablePointerChain< NEXT >::next

Next pointer.


The documentation for this struct was generated from the following file: