Tim Blechmann | 5 Jul 11:25
Favicon

[flyweight] rw_locking policy patch for review

i have implemented a rw_locking policy for flyweight factories, based on
boost::shared_mutex. to achieve that, i had to adapt the factory
interface ...

joaquín, would it be possible for you to review the patch? it is based
against the version of flyweight from the boost sandbox svn ...

best, tim

--
tim <at> klingt.org
http://tim.klingt.org

Cheat your landlord if you can and must, but do not try to shortchange
the Muse. It cannot be done. You can't fake quality any more than you
can fake a good meal.
  William S. Burroughs
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Favicon
Gravatar

Re: [flyweight] rw_locking policy patch for review

________________________________________
De: Tim Blechmann [tim <at> klingt.org]
Enviado el: sábado, 05 de julio de 2008 11:26
Para: boost <at> lists.boost.org; JOAQUIN M. LOPEZ MUÑOZ
Asunto: [flyweight] rw_locking policy patch for review

> i have implemented a rw_locking policy for flyweight factories, based on
> boost::shared_mutex. to achieve that, i had to adapt the factory
> interface ...
>
> joaquín, would it be possible for you to review the patch? it is based
> against the version of flyweight from the boost sandbox svn ...

Hello Tim,

First of all, thank you for taking interest in Boost.Flyweight to the point
of implementing this very interesting extension. I've got several
comments on your code and a couple of requests:

- The patch looks very clean (which I'm happy about, cause that
probably means the original code is understandable enough for others
to work on it). After a cursory look I found what I think it's an error
and also a design issue:
  * The error is in flyweight_core::erase(). You have moved the invocation
  to check(h) outside of the write lock, which can cause a race condition:
     · Thread A destroys the last flyweight associated to some value x.
    check(h) passes as there are no more references and just when factory.
    erase() is about to be called the thread is interrupted.
    · Thread B creates a flyweight with value x.
    · Thread A resumes and the entry with x is destroyed leaving a dangling
(Continue reading)

Tim Blechmann | 6 Jul 12:33
Favicon

Re: [flyweight] rw_locking policy patch for review

thanks for having a look at my patch ...

>   * The error is in flyweight_core::erase(). You have moved the
>   invocation to check(h) outside of the write lock, which can cause a
>   race condition:
>      · Thread A destroys the last flyweight associated to some value x.
>     check(h) passes as there are no more references and just when
>     factory. erase() is about to be called the thread is interrupted. ·
>     Thread B creates a flyweight with value x. · Thread A resumes and
>     the entry with x is destroyed leaving a dangling reference in B.

i see your point ... double-checking before erasing value x should work 
around this issue ...

>   * The design issue has to do with your moving all the knowledge of the
>   locks to the factory itself. As I envision the design, all the lock
>   stuff should be made by flyweight_core and factories should be kept as
>   dumb as possible: see for instance that you've got a fair amount of
>   code repetition across the insert() and erase() memfuns of the
>   different factories, this is precisely a sign that you can factor this
>   out, and the proper place (IMHO) to have it is in flyweight_core.

i see your point, it would be possible to extend the factory api with a 
find() memfun ... 
i didn't do that for now, since i think, this way certain factories could 
implement an more efficient insert() than a combined find()/insert() 
pair ...

> Apart from this the patch is nice and I'd like to use it as inspiration
> (with your permission) to enhance the lib in the future when rw locks
(Continue reading)

Favicon
Gravatar

Re: [flyweight] rw_locking policy patch for review

________________________________________
De: boost-bounces <at> lists.boost.org [boost-bounces <at> lists.boost.org] En nombre de Tim Blechmann [tim <at> klingt.org]
Enviado el: domingo, 06 de julio de 2008 12:33
Para: boost <at> lists.boost.org
Asunto: Re: [boost] [flyweight] rw_locking policy patch for review

> >   * The error is in flyweight_core::erase(). You have moved the
> >   invocation to check(h) outside of the write lock, which can cause a
> >   race condition:
> [...]
>
> i see your point ... double-checking before erasing value x should work
> around this issue ...

Yep.

> >   * The design issue has to do with your moving all the knowledge of the
> >   locks to the factory itself. As I envision the design, all the lock
> >   stuff should be made by flyweight_core and factories should be kept as
> >   dumb as possible
> [...]
>
> i see your point, it would be possible to extend the factory api with a
> find() memfun ...
> i didn't do that for now, since i think, this way certain factories could
> implement an more efficient insert() than a combined find()/insert()
> pair ...

Well, there's always that tradeoff lurking in... I prefer to keep the design
orthogonal and risk losing that potential improvement (which hopefully
(Continue reading)


Gmane