title: delete boost function while in use
body: <p>I have a situation where a boost::function and boost::bind (actually a std::tr1::function and bind) are being deleted while still in use.  Is this safe?  I would normally avoid it, but the offending code is a bit entrenched and my only other option is adding a new thread.</p>
  
  <pre><code>typedef function&lt;int(int)&gt; foo_type;
  
  foo_type* global_foo = NULL;
  
  int actual_foo( int i, Magic* m )
  {
      delete global_foo;
      return m-&gt;magic(i);
  }
  
  int main()
  {
       Magic m;
      global_foo = new foo_type( bind( &amp;actual_foo, _1, &amp;m );
  
      return (*global_foo)(10)
  }
  </code></pre>
  
  <p>The bound parameters are always plain integral types (an int and a pointer in the real code), and not references.</p>