by sanjoy_das · 11y ago · 0 comments
Thread1:
Obj = Heap->field;
Heap->field = null;
// reduced a reference so:
if (AtomicDecrement(Obj->refcount) == 0) {
free(Obj);
}
Since you'll be racing with Thread2:
Obj = Heap->field;
// stalls, and Thread1 deletes Obj
AtomicIncrement(Obj->refcount)
The only satisfactory solution to this that I'm aware of is to use
hazard pointers, and that is a fairly complex bit of logic. Maybe
there's a better solution to this, but I've not come across one.No comments yet.