[cpp-threads] modes
Alexander Terekhov
alexander.terekhov at gmail.com
Sat May 7 17:56:44 BST 2005
On 5/7/05, Alexander Terekhov <alexander.terekhov at gmail.com> wrote:
> Err.
>
> On 5/7/05, Alexander Terekhov <alexander.terekhov at gmail.com> wrote:
> > On 5/7/05, Doug Lea <dl at cs.oswego.edu> wrote:
> > [...]
> > > 2. There's very little motivation to define CAS-with-acquire only.
> > [...]
> > > Also, as always, I just don't think that explicit LL/SC is worth
> > > exposing. LL/SC instructions tend to have so many restrictions and
> > > quirks that the just about only thing it is good for is CAS/weakCAS
> > > emulation
> >
> > I disagree on both accounts.
> >
> > http://sourceware.org/ml/pthreads-win32/2004/msg00120.html
> > (msync::acq can be replaced with msync::acq, and hopefully smart
>
> (msync::acq can be replaced with msync::ccacq, and hopefully smart
>
> > compiler can hoist {lw}sync out of attempt_update loop).
and also...
> >
> > CAS-based version looks similar, but is less effecient when CAS
> > is emulated on top of LL/LR-SC.
> >
> > void lock() {
> > int old = load_naked(&m_lock_status);
> > if (old || old = cas_ccacq(&m_lock_status, 0, 1)) {
> > do {
> > while (old < 0 || old = cas_naked(&m_lock_status, 1, -1)) {
> > m_retry_event.wait(); // acquire semantics
> > old = load_naked(&m_lock_status);
> > }
> > } while (old = cas_ccacq(&m_lock_status, 0, -1));
> > }
> > }
> >
> > void unlock() {
> > int old = load_naked(&m_lock_status);
> > if (old < 0 || cas_rel(&m_lock_status, 1, 0) < 0) {
> > store_rel(&m_lock_status, 0);
...can eliminate redundant {lw}sync on store_rel().
> > m_retry_event.set(); // release semantics
> > }
> > }
If not,
void unlock() {
if (swap_rel(&m_lock_status, 0) < 0)
m_retry_event.set(); // release semantics
}
might work better. Although it's on slow path and doesn't matter that much.
regards,
alexander.
P.S. Mysterious lack of xchg.rel on Itanic (they only have xchg.acq)
aside for a moment. ;-)
More information about the cpp-threads
mailing list