Hazard pointers needed with GC ?
Walter Bright
newshound2 at digitalmars.com
Wed Dec 7 14:23:26 PST 2011
On 12/7/2011 9:02 AM, Martin Nowak wrote:
> I implemented a lock-free doubly linked list some time ago.
> I omitted the use of hazard lists because flagging the lowest
> bit would still make a valid pointer into the list node.
> Afterwards I found that http://www.d-programming-language.org/garbage.html
> explicitly states:
> p = cast(void*)(cast(int)p | 1); // error: undefined behavior
>
> Is this really needed? Guess the current GC would work properly.
>
> Also if a list node were
> Node(T)
> {
> ubyte[2] data;
> T t;
> }
> Than both a pointer to data[0] as well as one to data[1] are valid
> and effectively hold the node.
If the GC runs a collection cycle while the pointer has that bit set, and
setting the bit causes it to point past the allocated data, then it will not
regard that data as being in use and will delete it.
An easy way to make it work right is to make sure that or'ing in the bit will
not cause the pointer to point past the object.
More information about the Digitalmars-d
mailing list