title: Using static mutex in a class
body: <p>I have a class that I can have many instances of. Inside it creates and initializes some members from a 3rd party library (that use some global variables) and is not thread-safe.</p>
  
  <p>I thought about using static boost::mutex, that would be locked in my class constructor and destructor. Thus creating and destroying instances among my threads would be safe for the 3rd party members.</p>
  
  <pre><code>
  
  class MyClass
  
  {
    static boost::mutex mx;
  
    // 3rd party library members
  public:
    MyClass();
    ~MyClass();
  };
  
  MyClass::MyClass()
  {
    boost::mutex::scoped_lock scoped_lock(mx);
    // create and init 3rd party library stuff
  }
  
  MyClass::~MyClass()
  {
    boost::mutex::scoped_lock scoped_lock(mx);
    // destroy 3rd party library stuff
  }
  </code>
  
  </pre>
  
  <p>I cannot link because I receive error:</p>
  
  <pre><code>undefined reference to `MyClass::mx`
  </code></pre>
  
  <ol>
  <li><p>Do I need some special initialization of such static member?</p></li>
  <li><p><strong>Is there anything wrong about using static mutex?</strong></p></li>
  </ol>
  
  <p><br>
  <strong>Edit:</strong>  Linking problem is fixed with correct definition in cpp</p>
  
  <pre><code>boost::mutex MyClass::mx;
  </code></pre>