TDPL, shared data, and Phobos

Brian Palmer d at brian.codekitchen.net
Tue Jul 20 12:41:31 PDT 2010


> > It probably wasn't very clear from my simplified example, but I'm looking to create a shared-reader-one-writer scenario. If I declare MyValue synchronized, only one thread can be inside the get() method at a time, which defeats the shared-reader requirement. Imagine this is a much larger more complex data structure, where get() requires walking through multiple levels of a tree and a binary search at the last level.
> > 
> 
> Yup, I get it. But there is one point in it: write is not atomic operation in sense that get() might return half written data, right?

No, that's why I want a read-write lock. Multiple threads can read the data, but writes take an exclusive lock.

http://en.wikipedia.org/wiki/Readers-writer_lock


More information about the Digitalmars-d mailing list