title: how can I lock entire class
body: <p>I have the following pseudo code:</p>
  
  <pre><code>class A:
      mutex lockForB
  
  class B:
      def __init__(self, A): //the type of A is class A
          lock(A.lockForB)
          # ...
          unlock(A.lockForB)
  
      # other function have the same locking
  </code></pre>
  
  <p>I understand from oop point of view it is very bad idea to use such design, but if I create lock inside class B I will not be able to put lock on creator of the class B.  Is there any better design for this? Thanks in advance.</p>