Boost logo

Boost :

From: renej_at_[hidden]
Date: 2002-07-10 03:57:55


seeing the discussion on shared_ptr ->*, I'd like to give one reason
why a configurable smart pointer should support operator->*, including
some extra's: making objects thread-safe by using a smart pointer
suppose for example a locking_ptr template that locks when dereferenced
and unlocks when the expression is done:

   class Type
   {
      // ....
      public:
         void some_method ();
      // ....
   };
   extern locking_ptr<Type> p;
   p->some_method(); // instance is locked during expression

   void (Type::*m)() = Type::some_method;
   (p->*m)(); // instance is locked when member function is executed

I think this is a very elegant way to introduce thread-safety and release
application programmers from numerous scoped_locks, guards, etc

I also looked at the Loki configurable smart pointer, but I didn't see
a way to make a "locking" pointer like this; to do so, the result type
of dereferencing and such is needed:

   locking_ptr_memfun_deref<T> locking_ptr<T>::operator->* (...);

where locking_ptr_memfun_deref<T> takes care of the actual locking
also:

   locking_ptr_deref<T> locking_ptr<T>::operator-> (...);

if "all" smart pointers provide the operator->* support, then
shared_ptr<T> and locking_ptr<T> as well as a raw pointer could be
in the same manner
I know that for each problem is a solution but due to my obsessive
urge to provide simple usage for application programmers I need
things like the locking_ptr and other smart pointers without the
need to have programmers to do different things with pointers, just
because some solution for that specific kind of smart pointer exists

This makes it easy making classes without worrying about thread-safety
and use them in single ot multiple thread environments
forgive the "loose" usage of the thread-safety concept; no flaming
please

just my 2 cents

renej


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