[cpp-threads] Alternatives to SC

Herb Sutter hsutter at microsoft.com
Sat Jan 13 22:59:57 GMT 2007


Peter wrote:
> Herb Sutter wrote:
> > So now let me cast the question this way, which I think finally puts
> > the finger on what's been bothering me:
> >
> >   Is an atomic variable a monitor?
> >
> > Or equivalently:
> >
> >   Does an atomic variable have internally-locked semantics?
>
> This is precisely one of the things that has been bothering me, but
> possibly not in the same way. In another formulation, the question is:
>
> If an atomic variable is equivalent (even performance-wise) to an ordinary
> variable protected by a lock, why do we need such atomic variables at
> all?

Because it's not as expensive as a lock, especially if you're just doing reads. For example, DCL is still a performance win. Right? As Hans wrote a few hours ago in another thread:

> I think that something with performance similar to the current Java
> volatile implementations is useful, since it adds no overhead on the
> reader side, and just mandates expensive writes.  I agree that if we
> cannot get hardware vendors to make an implementation along those lines
> work reliably, we have a problem.

Herb




More information about the cpp-threads mailing list