Re: C++, mutable member cache synchronization via double-checked-guard - is my idea correct?
- From: "Chris Thomasson" <cristom@xxxxxxxxxxx>
- Date: Mon, 28 Apr 2008 15:03:24 -0700
"Mirek Fidler" <cxl@xxxxxxxxxx> wrote in message news:4bd1a0e5-2a9f-4996-b4ab-597e51c490bc@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Apr 28, 1:51 am, "Chris Thomasson" <cris...@xxxxxxxxxxx> wrote:
> "Mirek Fidler" <c...@xxxxxxxxxx> wrote in message
>
> news:d62857bf-8475-4882-bd1c-f3aaa063f004@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> On Apr 27, 4:27 pm, "Dmitriy V'jukov" <dvyu...@xxxxxxxxx> wrote:
>
> > > On 27 ÁÐÒ, 17:14, Mirek Fidler <c...@xxxxxxxxxx> wrote:
>
> > > > > I see little problem here. You are loading double value which > > > > > can be
> > > > > concurrently modified. Store and load of 'sinx' must be atomic.
>
> > > > Pardon my ingorance, but is not it guaranteed by mutex?
>
> > > Modification always guarded, but load of value in Get() usually not
> > > guarded. So you can load value in middle of modification.
> > Ah, I see. You suppose that the problem is concurrent Set with Get?
> > But that cannot happen by interface defintion - client code would have
> > to protect against this e.g. using some for of rwlock (as correctly
> > demonstrated by Peter Dimov's post).
>
> Well, why not use an opportunistic upgradeable rwlock? If client code > needs
> to synchronize access anyway, I don't see why this something like this > could
Ehm, ops.
I guess we are just having terminology mismatch. In fact, what you
propose is exactly what I have wanted since the very beginning. (Just
reread the first post :)
I guess the only difference is that you are using a sort of spinlock
to implement DCL (or DCL-like algorithm) instead of Mutex, right?
It's not really a spinlock, well, its like a adaptive mutex with a bounded spin-count of 1. The reader tries to upgrade it self to a writer. If that fails, it releases read-access and acquires write, re-evaluates the dirty flags and acts accordingly. This would need to be documented. Since reader access was acquired externally, well, when it fails to upgrade and does the rdunlock-wrlock it invalidates the previously acquired read-access.
And also, my DCL implementation was a little bit less effective
because those memory barriers are not really necessarry, as they are
performed by rwlock synchronization primitives in the client code
anyway.
Your going to need at least release barrier before you set the flag to false.
.
- References:
- C++, mutable member cache synchronization via double-checked-guard - is my idea correct?
- From: Mirek Fidler
- Re: C++, mutable member cache synchronization via double-checked-guard - is my idea correct?
- From: Chris Thomasson
- Re: C++, mutable member cache synchronization via double-checked-guard - is my idea correct?
- From: Chris Thomasson
- Re: C++, mutable member cache synchronization via double-checked-guard - is my idea correct?
- From: Dmitriy V'jukov
- Re: C++, mutable member cache synchronization via double-checked-guard - is my idea correct?
- From: Mirek Fidler
- Re: C++, mutable member cache synchronization via double-checked-guard - is my idea correct?
- From: Dmitriy V'jukov
- Re: C++, mutable member cache synchronization via double-checked-guard - is my idea correct?
- From: Mirek Fidler
- Re: C++, mutable member cache synchronization via double-checked-guard - is my idea correct?
- From: Chris Thomasson
- Re: C++, mutable member cache synchronization via double-checked-guard - is my idea correct?
- From: Mirek Fidler
- C++, mutable member cache synchronization via double-checked-guard - is my idea correct?
- Prev by Date: Re: Multiplatform threadsafe reference counter
- Next by Date: Re: C++, mutable member cache synchronization via double-checked-guard - is my idea correct?
- Previous by thread: Re: C++, mutable member cache synchronization via double-checked-guard - is my idea correct?
- Next by thread: Re: C++, mutable member cache synchronization via double-checked-guard - is my idea correct?
- Index(es):
Relevant Pages
|