[Python-Dev] PyWeakref_GetObject() borrows its reference from... whom?

Chris Angelico rosuav at gmail.com
Mon Oct 10 18:58:38 EDT 2016


On Tue, Oct 11, 2016 at 9:52 AM, MRAB <python at mrabarnett.plus.com> wrote:
>> Also, I don't know when it would ever be safe to release the "memory
>> deallocation lock".  Just because it's safe for your thread doesn't mean
>> it's safe for another thread.  And if you do it on a thread-by-thread
>> basis, in the above example it might be safe from thread B's perspective
>> to release its "memory deallocation lock", but as illustrated that can
>> have an effect on thread A.
>>
> The deallocation lock could be a counter. Doomed objects would be
> collectable when it's zero.

Yeah, which is why I described it as a "guard". As long as you have
atomic increment/decrement (ie if two threads simultaneously try to
increment it, it WILL go up by two), it should be fine. Well, that
part should, anyway.

ChrisA


More information about the Python-Dev mailing list