[cpp-threads] D2335 (sequential consistency proof) revision

Boehm, Hans hans.boehm at hp.com
Fri Aug 24 23:20:41 BST 2007


 

> -----Original Message-----
> From: cpp-threads-bounces at decadentplace.org.uk 
> [mailto:cpp-threads-bounces at decadentplace.org.uk] On Behalf 
> Of Herb Sutter
> Sent: Friday, August 24, 2007 3:06 PM
> To: C++ threads standardisation
> Subject: Re: [cpp-threads] D2335 (sequential consistency 
> proof) revision
> 
> Hans wrote:
> > > Here's another possible way out of this.  I'm not 100% 
> sure this is 
> > > correct yet, but it seems like it on first glance:
> > >
> > > We allow trylock and timedlock to fail spuriously, even 
> if the lock 
> > > was never held.
> [...]
> > > If we do this, I believe we no longer need acquire 
> semantics for a 
> > > failed trylock.
> 
> Howard wrote:
> > It sounds good to me.  I'm not an expert in the visibility 
> area so I'd 
> > like to double check my understanding.
> >
> > This code which takes two locks/mutexes and locks them without 
> > deadlock, in part by using try_lock, is not affected by Hans'
> > proposal, right?
> 
> Right.
> 
> > template <class L1, class L2>
> > void
> > lock(L1& l1, L2& l2)
> > {
> >      while (true)
> >      {
> >          l1.lock();
> >          if (l2.try_lock())
> >              break;
> >          l1.unlock();
> >          l2.lock();
> >          if (l1.try_lock())
> >              break;
> >          l2.unlock();
> >      }
> > }
> 
> The only change Hans is proposing is that a failed try_lock 
> doesn't have ordering guarantees, which doesn't affect this 
> example because the try_lock's have nowhere to be reordered 
> to anyway because they can't move out of the tightly 
> enclosing lock/unlock critical sections.
Just to be clear:  I am suggesting that, as far as the programmer is
concerned, the try_lock()s can fail when they don't have to, and hence
this code can go around the loop extra times.  But that doesn't affect
correctness of the code.

Hans
> 
> Herb
> 
> 
> --
> cpp-threads mailing list
> cpp-threads at decadentplace.org.uk
> http://www.decadentplace.org.uk/cgi-bin/mailman/listinfo/cpp-threads
> 



More information about the cpp-threads mailing list