Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-01-26 18:48:04


Allison Floyd wrote:
> Hello, the list.
>
> After some digging through the bind and mem_fn documentation, I have
> been unable to figure out whether I'm attempting to do something
> impossible or not. I've created a thread-safe variant of shared_ptr
> that uses Alexandrescu's LockingProxy to ensure that access to the
> contained object through operator-> correctly locks and unlocks the
> pointee object. In all respects save one, this "shared_locking_ptr"
> is syntactically equivalent to boost::shared_ptr. The one thing it
> cannot do is dereference the pointer via operator* (I can't figure out
> how to return something from operator* that remains in scope (and thus
> locked) long enough for the operation to complete). All well and good
> so far.
>
> Where I'm trying to use this beast is in boost::signals via bind (and
> therefore mem_fn). I'd like to connect a member function of an object
> to the signal through my shared_locking_ptr, so that when the signal
> fires it automatically locks the object, invokes the member function,
> and then unlocks. Shared pointers to objects are valid arguments to
> mem_fn; my shared_locking_ptr isn't, alas, apparently because it
> requires the operator* mentioned above.

mem_fn uses get_pointer(sp) to obtain a "raw pointer" which is then used as
a first argument to operator->*. If you return a locking proxy from your
get_pointer overload and implement operator->* for your locking proxy, it
should work as you want.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net