|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2007-08-22 19:14:02
on Wed Aug 22 2007, Howard Hinnant <howard.hinnant-AT-gmail.com> wrote:
> If a given bit of code waits on a single cv with multiple mutexes in
> a legal fashion when the condition is default constructed. Why is
> that same code necessarily a logic error if the constructor is
> changed?
Was that supposed to be one sentence?
The reason is, "Peter said so." In other words, if you accept Peter's
modification, the contract says "if you construct it this way, it's a
logic error to use it that way."
I don't see a problem with that.
I'm actually not sure Peter doesn't mean to make it a logic error in
both cases.
> A contrived example (sorry, best I can do on short notice): The
> user, via std::cin, selects a mutex to wait on. He is supposed to
> pick the right one. But he makes a mistake and picks the wrong one.
> Logic error or exceptional runtime condition? If a logic error, why
> is it not still a logic error if the condition is default
> constructed? Simply because we declare it to be so in the
> documentation?
Absolutely!
Look, writing 1/x is a logic error if x==0. If x comes from user
input, you add input validation and reject it before you try to do the
division.
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk