Matt Taylor
8/8/2004 10:49:00 PM
"Ronald Landheer-Cieslak" <ronald@landheer.com> wrote in message
news:2ni98gF18vknU1@uni-berlin.de...
> Matt Taylor wrote:
>
> > So, I've read a bit of the information that was posted in my last
> > question -- many thanks to all who replied! I was looking at SMR,
> > particularly because the guarantees it makes are attractive and because
the
> > performance is good. I pulled up a paper by Maged M. Michael on SMR
("Hazard
> > Pointers: Safe Memory Reclamation for Lock-Free Objects") and have a
> > rudimentary understanding of how it works now.
> >
> > SMR cannot ever free hazard pointer structures, right? If I hit a
degenerate
> > case and have to allocate a large number of these, then they are
permanently
> > locked in.
> The per-thread hazard pointers can be deleted when the thread dies (when
> there is no longer any need for them) - though that depends on how you
> implement them. In MM Micheal's proposed implementation, IIRC, they're
> in a static array, so their life-time would be the same as the process'
He also mentions a linked list extension but gives no information with
regard to freeing the HPs in the list. His pseudocode only allocates and
releases them; it never frees.
So in your libmemory, the relevant functions are hptr_register and
hptr_free? What would happen if a thread were exiting as other threads were
traversing the HP list? Seems to me that it's possible to crash if a thread
was switched out while traversing the HP list and another thread exited.
> As for whatever those pointers point to - as long as there are hazardous
> references to an object, the object's memory can not be freed.
>
> > Also, perhaps my understanding is flawed, but does SMR put no bound on
the
> > amount of time before memory is reclaimed in the absense of thread
failures?
> > What I mean is that it seems that an object may be marked for deletion
and
> > still not deleted even if all hazard pointers to it are released. If
hazard
> > pointers still point to the object when it is marked for deletion, then
it
> > is only queued for deletion. Until the thread that marked it for
deletion
> > returns to re-evaluate the object, it will not be deleted. If the thread
> > does not return to re-evaluate the object for deletion, then its
deletion
> > may be postponed indefinitely, even though the maximum number of objects
for
> > which this can occur is bounded.
> The only way you could "fix" this is by allowing other threads to access
> the same dlist - i.e. make it a single, global list. It's possible, but
> it presents a chicken-and-egg problem if you want that list to be
> dynamic and non-blocking.. (I.e. how are you going to handle its memory
> - with SMR?)
[...]
What I was thinking was to have threads pass off responsibility for the
object. HPs would be extended with an ownership tag. If the tag is set, the
thread that owns the HP has to execute a scan on the object when the HP is
cleared. The maximum time complexity for deletion of one object is linear --
it is equal to the length of the HP list at the time the object was marked
for deletion.
Upon finding an HP that referenced an object pending deletion, the thread
would test-and-set its ownership tag and then verify that the HP was still
active. If not, then the ownership tag is checked to see whether or not the
other thread saw the test-and-set before it freed the HP. If still set, then
the search continues as the HP has been freed and the object has not. In the
other two cases, the responsibility of deleting the object has been
successfully passed to the thread that owns the HP.
While I have talked of test-and-set and an ownership flag, I suspect a
working implementation would need to use CAS or possibly a double-width CAS
in order to prevent race conditions on the hand-off. The problem is, of
course, that an object can be passed off to an HP that is in the middle of
being recycled (though not yet seen by the thread). I have a few ideas on
alternate ways to implement this (perhaps an auxillary pointer that is set
to point to the object to indicate possession), but as of yet none that
would actually work.
-Matt