4 ms·
Yeah, I'm not exactly getting all the complexity here. I'm digging the 2 reference counters, that makes sense to me, but I don't know why it isn't something mo
by cogman10 5y ago
Yeah, I'm not exactly getting all the complexity here.
I'm digging the 2 reference counters, that makes sense to me, but I don't know why it isn't something more like:
"every time a new thread takes a reference, atomic +1, every time a new thread's local count hits 0, atomic -1. If the shared reference is 0, free".
IDK what special purpose the flags are serving here.
- deleted 5y ago[deleted]
- jeremyjh 5y agoMost objects are never shared so there would be a performance impact from incrementing (and decrementing) an atomic counter even just once.
- jetrink 5y agoThat is true, but what if the shared count were initialized to one and the creator thread frees an object when the shared count is equal to one and the local count is decremented zero? (Since it knows it holds one shared reference.) Then the increment and decrement would be avoided for non-shared objects.
- a1369209993 5y agoI probably should have mentioned that explicitly; edited.
- kzrdude 5y agoTo have one local count per thread would add memory overhead, I think? In his solution there are only two counters per object, local and shared. Any other thread can't know if it's the first time or not it's taking a reference to an object.