From: shiwei xu (xushiweizh_at_[hidden])
Date: 2008-05-17 05:24:05
> > 1. Lock-free free list (workarounds ABA problem).
> i didn't read all the code, but in tagged_ptr::set you write:
> Type vTag = m_p; // NOTE: getting 'tag' before getting 'data'!
> Type vOld = m_p;
> ... i am not sure, whether it is necessary to get tag before data, but if
> you need to do that, you have to add a memory barrier, otherwise compiler
> or cpu may reorder the memory access ...
Suppose we write the following code:
Type vOld = m_p;
Type vTag = m_p;
atomic if (m_p == vOld && m_p == vTag) then set m_p = vNew, m_p
Let's image the following executing order:
1. p1: vOld1 = m_p;
2. p2: vOld2 = m_p;
3. p2: vTag2 = m_p; // = Tag
4. p2: atomic if (m_p == vOld2 && m_p == Tag) then set m_p = vNew2,
m_p = Tag+1
5. p1: vTag1 = m_p; // = Tag+1
6. p1: atomic if (m_p == vOld1 && m_p == Tag+1) then set m_p =
vNew1, m_p = Tag+2
Clearly, if vNew2 == vOld1, then it is another ABA problem.
So, we should read Tag before reading Data.
btw, if you are using the stack just as free list, i don't think you need
> any aba prevention ... also, what about grabbing the code from my
> freelist implementation?
I wrote lock-free codes for the first time. So I didn't use your
implementation for exercises. :)
And your freelist implementation don't fit for me. I need a customizable
freelist to specify Alloc implementation. It seems like this:
template <typename T, typename Alloc, std::size_t max_size = 64>
BTW, I don't know why free list don't need any ABA prevention. And in your
freelist implementation I think that
tagged_ptr<struct freelist_node> next;
Here we don't need a tagged_ptr.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk