std.container.BinaryHeap + refCounted = WTF???
Steven Schveighoffer
schveiguy at yahoo.com
Wed Nov 17 09:03:33 PST 2010
On Wed, 17 Nov 2010 11:58:20 -0500, Sean Kelly <sean at invisibleduck.org>
wrote:
> Steven Schveighoffer Wrote:
>>
>> There is specific code in array appending that locks a global lock when
>> appending to shared arrays. Appending to __gshared arrays from multiple
>> threads likely will not work in some cases though. I don't know how to
>> get around this, since the runtime is not made aware that the data is
>> shared.
>
> The shared attribute will have to become a part of the TypeInfo, much
> like const is now. Knowing whether data is shared can affect where/how
> the memory block is allocated by the GC, etc.
shared is part of it, but __gshared is not.
Since __gshared is the hack to allow "bare metal" sharing, I don't see how
it can be part of the type info.
The issue is that if you append to such an array and it adds more pages in
place, the block length location will move. Since each thread caches its
own copy of the block info, one will be wrong and look at array data
thinking it's a length field.
Even if you surround the appends with a lock, it will still cause problems
because of the cache. I'm not sure there's any way to reliably append to
such data from multiple threads.
-Steve
More information about the Digitalmars-d
mailing list