How to use lambda capture with lock?
<p>In the code below, the member variable (match_room_list_) is a shared resource. So I used a mutex.</p>

<p>But locking confuses me.</p>

<p>Should I use lock or not in an inner lambda function?</p>

<pre><code>void room::join_room(int user_id) 
{
   std::lock_guard&lt;std::recursive_mutex&gt; lock(mutex_);
   std::shared_ptr&lt;match_room&gt; find_room = nullptr;

   for (auto iter : match_room_list_)
   {
      if (false == iter.second-&gt;is_public_room())
      {
            continue;
      }

      if (true == iter.second-&gt;is_full())
      {
            continue;
      }

      find_room = iter.second;
      break;
   }

   // Something

   // async ( other thread call this lambda function )
   // call database
   database_manager::get_instance().join_room(find_room-&gt;get_room_id(), user_id, [=](bool success, std::string room_id, std::vector&lt;int&gt; user_id_list)
   {  
      // How do you think I should using lock? 
      // std::lock_guard&lt;std::recursive_mutex&gt; lock(mutex_);

      // shared resource
      match_room_list_[room_id].join_user(user_id); 

      response_join_room_ntf(room_id, user_id_list);
   }
}
</code></pre>