Cannot take the .keys of shared AA. Is this a regression in 2.087 or a feature?

bauss jj_1337 at
Thu Aug 15 20:12:04 UTC 2019

On Thursday, 15 August 2019 at 19:51:30 UTC, Jonathan M Davis 
> n Thursday, August 15, 2019 11:33:06 AM MDT Piotr Mitana via 
> Digitalmars-d- learn wrote:
>> Code:
>> import std;
>> shared(string[string]) dict;
>> void main()
>> {
>>      dict.keys;
>> }
>> Error:
>> /dlang/dmd/linux/bin64/../../src/druntime/import/object.d(3417):
>> Error: cannot implicitly convert expression aa of type
>> shared(string[string]) to const(shared(string)[string])
>> onlineapp.d(7): Error: template instance
>> `object.keys!(shared(string[string]), shared(string), string)`
>> error instantiating
>> Before D 2.087 it compiled - is this a regression?
> Not being able to implicitly convert to const is a bit odd, but 
> arguably, nothing should ever be called on a shared AA anyway. 
> If an operation isn't thread-safe, then it shouldn't work with 
> shared. To use a shared object safely, you have to protect 
> access to it with a mutex or some other synchronization 
> mechanism, after which you would normally cast away shared to 
> operate on the object as thread-local while the lock is in 
> place and then release the lock when you're done (also making 
> sure that no thread-local references exist when the lock is 
> released). Because keys is not at all thread-safe, I'd strongly 
> argue that it should not work on a shared AA, and if it does, 
> that's a bug.
> - Jonathan M Davis

D really needs some official thread-safe implementations of 
containers, hashmaps etc.

More information about the Digitalmars-d-learn mailing list