title: boost::mutex / How to test if a mutex is locked
body: <p>I know, I know, the title of my message may seem provocative, since 
  boost::mutex purposefuly do not expose lock / unlock (in order to avoid dead locks).</p>
  
  <p>However the boost documentation is quite short on these aspects (to say the least), so I am asking if anyone can help me in the following use case.</p>
  
  <p>Suppose you have a class Foo, which has :<br>
  - a destructor that takes some time to complete<br>
  - a method that is called by a distinct thread, but should not be called during destruction  </p>
  
  <pre><code>class Foo
  {
   public:
  
    virtual ~Foo()
    { 
      //Time consuming operations here
    }
  
  
    //Method called by a timer belonging to a distinct class 
    void OnTimer()
    {
      //Other time consuming stuff. Should not be called during destruction !
    }  
  
  
  }; 
  </code></pre>
  
  <p>I tried (with no success) to implement a version based on boost::mutex </p>
  
  <pre><code>//boost::mutex implementation
  class Foo
  {
  public:
    Foo()
    {
    }
  
    virtual ~Foo()
    { 
      {
        boost::mutex::scoped_lock lock(mDisposingMutex);
        //Time consuming operations here
      }
    }
  
  
    //Method called by a timer belonging to a distinct class 
    void OnTimer()
    {
      {
        //Imaginary code here: mutex::locked() method is private !!!
        if ( ! mDisposingMutex.locked()) 
          return;
      }    
      //Other time consuming stuff. Should not be called during destruction !
    }  
  
  private:
    boost::mutex mDisposingMutex; 
  }; 
  </code></pre>
  
  <p>Am I totally wrong? Can anyone tell me how this is supposed to be done with boost::mutex?</p>
  
  <p>Thanks !</p>