Sharing Ref Counted Containers

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Aug 4 18:20:36 PDT 2010


On 08/04/2010 08:02 PM, dsimcha wrote:
> I noticed that std.container.Array uses completely unsynchronized reference
> counting.  Does that mean that it's basically impossible to share it across
> threads without introducing race conditions into the reference counting code,
> even if you synchronize on other updates?
>
> Are there any plans to make Array and future ref counted containers shareable?
>   If not (I'm not saying that making them shareable is necessarily worth
> doing), I think there should be a large warning against casting these to
> shared.  Usually, when you cast a data structure to shared, you can write
> working code as long as you properly synchronize all updates to the data
> structure.  However, because updates to the ref count field are happening
> under the hood in an invisible fashion, no matter how properly synchronized
> updates to the contents of the ref-counted container are, you basically can't
> properly synchronize updates to the ref count field.

There are no plans to make Array a shared type. A shared container would 
have a very different interface to begin with. Sharing Array objects is 
not recommended.

Andrei


More information about the Digitalmars-d mailing list