Hazard pointers needed with GC ?

Martin Nowak dawg at dawgfoto.de
Wed Dec 7 12:32:52 PST 2011


On Wed, 07 Dec 2011 18:28:59 +0100, deadalnix <deadalnix at gmail.com> wrote:

> Le 07/12/2011 18:02, Martin Nowak a écrit :
>> 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.
>>
>> martin
>
> When doing so, you should anyway have a local pointer to that data. So  
> it will not be collected until you release that local pointer, when the  
> flagged one is already removed.
>
That's exactly what a hazard pointer is used for.
Now the question is if the flagged pointer still points to
valid memory in the same object (union aliased), there should
be no need for thread local hazard pointers.

> Flagged pointer is a temporary state. It is usefull because falgging can  
> be done as an atomic operation. But the flagged pointer is not here to  
> stay. It is here to mention to others thread that an ongoing operation  
> is concurently running.


More information about the Digitalmars-d mailing list