|
Boost : |
From: Reid Sweatman (borderland_at_[hidden])
Date: 2000-08-11 18:18:49
> -----Original Message-----
> From: William Kempf [mailto:sirwillard_at_[hidden]]
> Sent: Friday, August 11, 2000 4:53 PM
> To: boost_at_[hidden]
> Subject: [boost] Re: Threads by Jeremy and Monitors in one?
> No matter what school of thought you follow there may be a valid
> reason to throw an exception here. I'm still on the fence, but I'll
> illustrate why an exception may be appropriate:
>
> void foo::bar()
> {
> mutex::trylock lock(mx);
> // We forget to check if we locked and proceed to access
> // shared resources here!
> }
>
> Using an exception will make a lot of code harder to deal with,
> especially since failing to lock isn't really an exceptional
> condition here, but not using an exception could lead to disaster.
>
> The only good thing is that it shouldn't be too likely that someone
> would fail to check the lock here, since they used a trylock instead
> of a simple lock.
I follow the Platonic School of Ideal Forms. That's why I swear at my
compiler so much <g>. Okay, I may not be remembering your most recent
example post for your mutex exactly, but wouldn't it make more sense to have
lock() return a Boolean? Or are you arguing that even if it did, some
people wouldn't bother to check its value? In that case, I guess an
exception makes sense. Are you using a throw decoration, or just letting
the exception trigger unexpected()? If the latter, I think I'd want a way
to remove the exception from release code, since you'd basically be using it
as a way of spotting bad thread usage. Why pay the performance penalty if
you've wrung all the bugs causing the mutex exceptions out in QA?
BTW, I apologize if I've misremembered your code and its intent; I read and
killed it earlier.
Reid Sweatman
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk