Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-09-21 18:58:02


From: "David Abrahams" <dave_at_[hidden]>
>
> Even short, hairy functions can be weird. What's going on here?
>
> template<class T> shared_ptr<T> make_shared(weak_ptr<T> const & r) //
> never throws
> {
> // optimization: avoid throw overhead
> if(r.use_count() == 0)
> {
> return shared_ptr<T>();
> }
>
> try
> {
> return shared_ptr<T>(r); // 1
> }
> catch(use_count_is_zero const &)
> {
> return shared_ptr<T>();
> }
> }
>
> How will use_count_is_zero get thrown at "1"?
> Oh, this is a thread-safety thing?
> A comment would be a big help here...

Will add.

> How about getting rid of the complication in case of BOOST_NO_THREADS?

Not that much difference in the generated code, and #ifdefs just clutter the
source. People hate #ifdefs. :-) I don't like the #ifdefs in
shared_count.hpp much either, but some compilers don't optimize out the
empty BOOST_NO_THREADS mutex in lwm_nop.hpp for some reason, and those
functions are performance critical.


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