TDPL, shared data, and Phobos
Brian Palmer
d at brian.codekitchen.net
Thu Jul 22 11:33:54 PDT 2010
Robert Jacques Wrote:
> On Tue, 20 Jul 2010 15:41:31 -0400, Brian Palmer <d at brian.codekitchen.net>
> wrote:
>
> >> > 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
>
> Have you tried core.sync.rwmutex? Also, please remember that CREW locks
> are not composable and can easily lead to dead-locks.
lol, yes, that's how this thread started was with a discussion of core.sync.rwmutex.
More information about the Digitalmars-d
mailing list