With ARC sharing objects across threads becomes trickier. First of
all, in the general case you'll have to do atomic increments and
decrements which tend to be fairly expensive, and they'll be sitting
right in the middle your core application logic. Secondly, if you're
sharing objects amongst threads, you cannot simply do:
Thread1:
Obj = Heap->field;
Heap->field = null;
// reduced a reference so:
if (AtomicDecrement(Obj->refcount) == 0) {
free(Obj);
}
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.
Since you'll be racing with
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.