Assoc Arrays

Jonathan M Davis jmdavisProg at gmx.com
Tue Jul 23 10:20:46 PDT 2013


On Tuesday, July 23, 2013 13:34:36 Bottled Gin wrote:
> Hello All
> 
> Are associative arrays in D thread-safe. Is it safe to access
> (read-write) a shared assoc array from multiple threads?

Unlike C/C++/Java/etc., by default, variables in D are thread-local. It's 
variables that are marked with the attributed "shared" which are shared across 
threads. So, you don't have to worry about thread safety unless you're dealing 
with variables which are shared, and in that case, AAs definitely aren't 
thread-safe on their own. You need to protect access to them with mutexes or 
synchronized blocks or the like.

> I assume they are not, since an assoc array is initialized to
> null. Is that going to change in future?

I'm afraid that I don't see what initializing to null has to do with thread-
safety. And while I'm sure that the implementation of AAs will be improved in 
the future, I don't expect how they fundamentally work to change.

- Jonathan M Davis


More information about the Digitalmars-d mailing list