Boost logo

Boost :

Subject: [boost] [variant] static_visitor deadlock
From: Andrew Hundt (athundt_at_[hidden])
Date: 2011-05-17 13:06:05


I believe I may have found a way to create a deadlock in static_visitor, but
it may be my own mistake.

It seems if I apply one static visitor within another with an extra call to
operator() that I use for shared_ptr objects, the program deadlocks in
apply_visitor_binary_invoke::internal_visit(). The template in my class
below is another static visitor object, so in essence I am creating an
effect similar to a java decorator using visitors. Here is a stripped down
version of the class with which the deadlock occurs:

/**
 * @class VisitorDecorator
 *
 * @brief decorates (wraps) a normal visitor
 */
template <typename T>
class VisitorDecorator : public boost::static_visitor<typename
T::result_type> {
  typedef typename T::result_type t_result_type;
public:
  VisitorDecorator(boost::shared_ptr<T> deviceCommandVisitor, std::string
filename):
    m_visitor(deviceCommandVisitor),
    m_filename(filename)
    {}

  /**
   * @brief strip shared pointers and handle the object itself
   */
  template <typename U, typename V>
  inline t_result_type operator()( boost::shared_ptr<U>& deviceP,
boost::shared_ptr<V>& commandP){

    return operator()(*deviceP,*commandP);
  }

  /**
   * @brief Connect the specified struct types to the log file
   */
  template<typename U, typename V>
  t_result_type operator()(U& device, V& command){

    return (*m_visitor)(device,command);
  }
private:
  boost::shared_ptr<T> m_visitor;
  std::string m_filename;
};

Does anyone have thoughts or suggestions, be it my fault or a bug in the
library?

Cheers!
Andrew Hundt


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