title: Using an object like a lock
body: <p>I have a library with my own lock_guard, mutex etc. (basically mutex is a wrapper for nativ mutexes. Now I want to update several objects with several threads which have a lock inside of them.</p>
  
  <p>Let's consider the class does look like that:</p>
  
  <pre><code>class ICanBeUpdated
  {
  public:
      friend mango::lock_guard&lt;ICanBeUpdated&gt;;
  
      ICanBeUpdated()
      {
          //set some values, etc
      }
  
      void Update()
      {
          //do something, takes some time
      }
  
  private:
      void lock() //required by the guard
      {
          m_Lock.lock();
      }
  
      void unlock() //required by the guard
      {
          m_Lock.unlock();
      }
  
      mango::mutex m_Lock; //regular mutex
  };
  </code></pre>
  
  <p>And I want to do something like that:</p>
  
  <pre><code>int main()
  {
      mango::archive::thread_pool pool(mango::getCPUCores(), true); //just a thread_pool
  
      lambda((ICanBeUpdated* actor)  //sorry my IDE has no c++11 support so I tricked my own lambda
      {
          mango::lock_guard&lt;ICanBeUpdated&gt; guard(*actor); //Locks the object like it were a mutex to block other stakeholders from changing it while it's updating
          actor-&gt;Update(); 
          return 0; 
      }, 1); //exp1
  
      mango::shared_ptr&lt;mango::vector&lt;ICanBeUpdated*&gt; &gt; Actors = getActors(); //creates a vector of actors
  
      for (int i = 0; Actors-&gt;size() &gt; i; ++i)
      {
          pool.run(exp1, Actors-&gt;at(i));
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Is it allowed to use a non-lock object with a lock inside like this?</p>
  
  <pre><code>mango::lock_guard&lt;ICanBeUpdated&gt; guard(*actor);
  </code></pre>
  
  <p>If no, why and do I always have to pass the mutex to the guard to lock it or should I implement another way to lock the actor?</p>