Reference counted containers prototype

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Dec 26 11:49:13 PST 2011


On 12/26/11 12:46 PM, Michel Fortin wrote:
> Although I am a little concerned by this
> small but important implementation detail:
>
> Your RefCounted destructor is racy.
>
> Just like other reference counted things in Phobos, if you somehow store
> a reference on the GC heap (as a class member for instance), the
> destructor for that reference struct is called from the GC thread and
> will decrement the counter from that thread, while another reference
> could play with the counter from another thread. I know you have plans
> for a general fix for that hole in destructors, but meanwhile it'd be
> wise to change the counter to a shared uint and use atomic operations to
> avoid low level races.

Does the current implementation unfreezes all threads before calling the 
destructors? If so, indeed there's a race.

BTW, the plan is to have the same thread that constructed objects to 
call their destructors; each thread would have a worklist of garbage 
objects to destroy. The list can be reduced during calls to allocation 
functions within each thread, and of course when the thread terminates.


Andrei


More information about the Digitalmars-d mailing list