Sharing unlocked, unchanging data between threads?

Steven Schveighoffer schveiguy at yahoo.com
Tue Aug 10 11:01:31 PDT 2010


On Tue, 10 Aug 2010 13:45:03 -0400, Chris Williams <aahz at seanet.com> wrote:

> I'm writing a fairly large, multithreaded application and some part
> of it is causing periodic access errors.
>
> Say that I have an associative array like:
>
> uint[ char[] ] nameToId;
>
> If I set all values before I start my threads going and never change
> anything after that point -- all access is read only -- is there any
> way that having multiple threads access it at the same time would
> mess anything up? I'm doing this in several places as locking a
> read-only data structure doesn't strike me as something which should
> be necessary. I don't know what D's associative arrays look like
> internally though, so perhaps it is dangerous to do. It would be a
> major hassle to port it all over to locking everything, to test if
> it fixes the problem. So, hopefully someone can say whether this is
> worth checking.

I don't see any reason why you'd need to lock it.  It should not be  
modified unless you change/insert a value or remove one.

It's likely something else causing the issue.

-Steve


More information about the Digitalmars-d-learn mailing list