3 ms·
> which is released (using the same decref code as other threads) when the local reference count goes to zero? (I may misunderstand your remark, as ‘releasing’
by Someone 5y ago
> which is released (using the same decref code as other threads) when the local reference count goes to zero?
(I may misunderstand your remark, as ‘releasing’ is a bit ambiguous. It could mean decreasing reference count and freeing the memory if the count goes to zero or just plain freeing the memory)
The local ref count can go to zero while other threads still have references to the object (e.g. when the allocating thread sends an object as a message to another thread and, knowing the message arrived, releases it), so freeing the memory when it does would be a serious bug.
Also, the shared ref count can go negative. From the paper:
> As an example, consider two threads T1 and T2. Thread T1 creates an object and sets itself as the owner of it. It points a global pointer to the object, setting the biased counter to one. Then, T2 overwrites the global pointer, decrementing the shared counter of the object. As a result, the shared counter becomes negative.
That can’t happen with the biased counter because, when it would end up going negative, the object gets unbiased, and the shared counter gets decreased instead.
That asymmetry is what ensures that only a single thread updates the biased counter, so that no locks are needed to do that.
- a1369209993 5y ago> I may misunderstand your remark, as 'releasing' is a bit ambiguous. The reference is released; ie the (atomic) reference count is decremented (and the object is only freed if that caused the atomic reference count to go to zero). > From the paper I missed that there was a paper and was referring to the proposed implementation in python that was described in TFA. IIUC, biased refcount (in paper) is local (in my description), and shared is atomic, correct? > the shared ref count can go negative And that makes sense. Thanks. (And also explains how to deal with references added by one thread and removed by another, when one of those threads is the object owner.)