[cpp-threads] D2335 (sequential consistency proof) revision
Paul E. McKenney
paulmck at linux.vnet.ibm.com
Sat Aug 25 21:47:50 BST 2007
On Sat, Aug 25, 2007 at 12:56:41AM +0300, Peter Dimov wrote:
> Boehm, Hans:
>
> > 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.
>
> I've found this specification a good idea in general for try_ operations.
> For example, a failed try_pop operation for a queue doesn't guarantee that
> the queue was empty; it might just have failed to try_lock an internal
> mutex.
>
> If you make try_* failures guarantee state, you might no longer guarantee
> that they never block.
Another advantage of this approach is that it allows "hostile" versions of
the try_ operations for debugging. These "hostile" versions spuriously
fail at random intervals, thus exercising code paths that are otherwise
extremely difficult to test.
On the other hand, there -are- useful algorithms that can take advantage
of guarantees that try_* failure implies a lock holder existed recently.
Nevertheless, such algorithms are quite rare, so I would vote for the
debuggability provided by allowing spurious failure.
Thanx, Paul
More information about the cpp-threads
mailing list