lib/quack_concurrency/mutex.rb
def lock(&block)
      raise ThreadError, 'Attempt to lock a mutex which is already locked by this thread' if owned?
      if block_given?
        lock
        begin
          yield
        ensure
          unlock
        end
      else
        @mutex.synchronize do
          @condition_variable.wait(@mutex) if locked?
          @owner = caller
        end
        nil
      end
    end
def lock(&block)
      raise ThreadError, 'Attempt to lock a mutex which is already locked by this thread' if owned?
      if block_given?
        lock
        begin
          yield
        ensure
          unlock
        end
      else
        @mutex.synchronize do
          @condition_variable.wait(@mutex) if locked?
          @owner = caller
        end
        nil
      end
    end
def lock ( & block ) raise ThreadError , 'Attempt to lock a mutex which is already locked by this thread' if owned? if block_given? lock begin yield ensure unlock end else @mutex . synchronize do @condition_variable . wait ( @mutex ) if locked? @owner = caller end nil end end
Creates a new {Mutex} concurrency tool.
 @return [Mutex]
 @raise [ThreadError] if current thread is already locking it
@overload lock
  Obtains the lock or sleeps the current thread until it is available.
  @return [void]
@overload lock(&block)
  Obtains the lock, runs the block, then releases the lock when the block completes.
  @raise [Exception] any exception raised in block
  @yield block to run while holding the lock
  @return [Object] result of the block
Creates a new { Mutex } concurrency tool .