Boost logo

Boost :

From: Russell Hind (rhind_at_[hidden])
Date: 2003-07-18 04:13:51


Daniel Frey wrote:
> Russell Hind wrote:
>
> I think that's not specific to locks/threads. In general, a library
> should *never* contain assert/exit/abort or anything else which stops
> the execution of a process immediately. An exception leaves the choice
> of how to react to the user - the library IMHO can't make a good
> decision as it doesn't know the context in which it is used.
>

I disagree. If the function is documented as having a pre-requisite
that the lock isn't already locked when calling lock, and vice-verase
for unlock, then it is a coding error and should be could be caught by
an assert.

If you search the boost source directory, you'll see that asserts are
used. I don't think they should be used for things that are out of the
users control (e.g. allocating resources etc) but for coding errors on
my part, I'd rather see asserts than exceptions.

mutex::scoped_lock Lock(Mutex);
     Lock.lock();

is just plain wrong and could easily be handled by an assert. It isn't
something that might go wrong at run-time and might not, this will
always fail and as such doesn't need an exception, IMHO.

Russell


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk