[phobos] Fwd: Re: Ruling out arbitrary cost copy construction?

Brad Roberts braddr at puremagic.com
Mon Nov 1 12:44:15 PDT 2010


On Mon, 1 Nov 2010, Steve Schveighoffer wrote:

> > From: Brad Roberts <braddr at puremagic.com>
> > 
> > Not relevant.  In either case the memory is still  referenced so won't be  
> >released.
> 
> Yes it is.  The item being destroyed is not the refcounted item, but the 
> reference to the refcounted item.
> 
> For instance, imagine a File member of a class object.  The File's destructor is 
> called when the object is destroyed in the GC, so it decrements the ref count in 
> the File struct, which could have a race with a thread which has a stack-based 
> File struct going out of scope.
> 
> I thought the GC does only mark with the world stopped, and then does sweep and 
> destructors after restarting the threads?  I somewhat remember the conversation 
> that we had on Tango IRC when Sean changed it.  It was introduced to fix a very 
> real problem -- if the destructors called some C code that tried to acquire a 
> lock that a stopped thread currently held, there would be a deadlock (this was 
> happening to someone, which is what prompted the discussion).  I don't think we 
> can go back.
> 
> -Steve

I stand corrected, and you're correct. Either mode has flaws.  Restart 
threads before destructors and you introduce races that only exist due to 
the gc.  Restart after destructors and you risk deadlocks caused by the 
gc.


More information about the phobos mailing list