title: Boost: mutex unlocking from any thread possible?
body: <p>I started using boost::thread recently (WinXP, VS10, BoostPro) and found that mutex can be unlocked by any thread, not by the thread that owns it only.
  Additionally it seams that the basic lock_guard + mutex combo is doing some internal counting of multiple lock() and unlock() but it is not a big issue I guess.</p>
  
  <p>Does somebody know why it was designed in such a way? Is it on purpose?
  (or maybe there is something wrong with my build environment / libs?)</p>
  
  <p>Example app:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;boost/thread.hpp&gt;
  
  using namespace std;
  
  
  class NamedThread
  {
  public:
      NamedThread(string name_, boost::mutex&amp; mtx_) :
        mtx(mtx_), name(name_) {}
  
      void operator ()()
      {
          for (int i = 0; i &lt; 10; ++i)
          {
              boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
              cout &lt;&lt; name &lt;&lt; endl;
  
              //boost::lock_guard&lt;boost::mutex&gt; guard1(mtx);
              //boost::lock_guard&lt;boost::mutex&gt; guard2(mtx);
  
              boost::unique_lock&lt;boost::mutex&gt; guard1(mtx);
              boost::unique_lock&lt;boost::mutex&gt; guard2(mtx);
          }
  
  
      }
  
      string name;
      boost::mutex&amp; mtx;
  };
  
  class UnlockerThread
  {
  public:
      UnlockerThread(string name_, boost::mutex&amp; mtx_) :
        mtx(mtx_), name(name_) {}
  
      void operator ()()
      {
          for (int i = 0; i &lt; 100; ++i)
          {
              boost::this_thread::sleep(boost::posix_time::milliseconds(3000));
              cout &lt;&lt; name &lt;&lt; ": unlocking" &lt;&lt; endl;
              mtx.unlock(); // !!! IT WORKS !!!
          }
      }
  
      string name;
      boost::mutex&amp; mtx;
  };
  
  
  int main()
  {
      boost::mutex mtx;
  
      NamedThread th2("Thread1", mtx);
      boost::thread t2(th2);
  
      UnlockerThread th3("UnlockerThread", mtx);
      boost::thread t3(th3);
  
      t2.join();
  
      char ch;
      cin &gt;&gt; ch;
      return 0;
  }
  </code></pre>
  
  <p>Thanks,</p>