title: Elegant pattern for scoped_lock to access resource?
body: <p>I have objects in containers that are access-controlled with mutexes.  I often do something like:</p>
  
  <pre><code>rsrc *r;
  {
      scoped_lock l(mtx);
      r = container.pop( );
  }
  // ... use r
  </code></pre>
  
  <p>(I use scoped_lock to ensure clean up after exceptions, etc.)  However, I don't like the { ... } block that's not part of an explicit control structure (it's only there to make a scope for the scoped_lock) and I don't like the null initialization of <em>r</em> followed by (probable but not certain) assignment in the { ... } block.</p>
  
  <p>I can do something like this:</p>
  
  <pre><code>inline rsrc *locked_pop( mutex &amp;mtx, container &amp;c ) { scoped_lock l(mtx); return c.pop( ); }
  </code></pre>
  
  <p>and then</p>
  
  <pre><code>rsrc *r = locked_pop( mtx, container );
  </code></pre>
  
  <p>which is OK, but I have situations where I need to get several items from same (or different) container, under the same lock.</p>
  
  <p>Do you know of an elegant, general way of doing this?  (This is not specifically a Boost question, but I'm using those libraries so a Boost-ism would be fine.)</p>