this method must be synchronized on @mutex, obviously
974160
def wait_for_result(timeout)
        # do the deadline maths
        time_to_stop = timeout ? (Time.now + timeout) : nil # slight time slippage between here
                                                            #
        until @result                                       #
          if timeout                                        # and here
            now = Time.now

            if @result
              return
            elsif (now >= time_to_stop)
              @result = TIMED_OUT
              return
            end

            @cond.wait(time_to_stop.to_f - now.to_f)
          else
            @cond.wait_until { @result }
          end
        end
      end
1040983
def transaction(force_sync = false, &block)
      # Ruby 1.9.3 does not support @mutex.owned?
      if @mutex.respond_to?(:owned?)
        force_sync = false if @mutex.locked? && @mutex.owned?
      else
        # If we allowed this in Ruby 1.9.3, it might possibly cause recursive
        # locking within the same thread.
        force_sync = false
      end
      if !force_sync && (@in_transaction || options[:without_mutex])
        block.call self
      else
        @mutex.synchronize do
          @in_transaction = true
          result = block.call
          @in_transaction = false
          result
        end
      end
    end
902207
private void handleWhereBlock(Method method) {
    Block block = method.getLastBlock();
    if (!(block instanceof WhereBlock)) return;

    new DeepBlockRewriter(this).visit(block);
    WhereBlockRewriter.rewrite((WhereBlock) block, this);
  }
1043730
private static void wait(Object lock, int timeout)
  {
    try {
      lock.wait(timeout);
    }
    catch(InterruptedException unused) {
      Thread.currentThread().interrupt();
    }
  }
485731
def signal
      synchronize do
        while(t = @threads.shift)
          if(t && t.alive? && t.stop?)
            t.wakeup
            break
          else
            next
          end
        end
      end
    end
366292
def submit_and_block(meth, *args)
      @mutex.synchronize do
        raise Exceptions::NotConnected if unhealthy?
      end

      cnt = Continuation.new(meth, *args)
      @reg.synchronize do |r|
        if meth == :state
          r.state_check << cnt
        else
          r.pending << cnt
        end
      end
      wake_event_loop!
      cnt.value
    end
521286
def nextResult
      result = nil
      @mutex.synchronize do
        result = @results.shift
        @progressMutex.synchronize{ @requestProgress.delete result.requestId } if result
      end
      result
    end
773163
def close_thread_queues
      still_active = false
      @mutex.synchronize do
        @thread_name_to_queue.each_value do |queue|
          if queue.active?
            queue.close
            still_active = true
          end
        end
      end
      return still_active
    end
527822
def synchronized(wrapped):
    """"""
    _lock = threading.RLock()

    @functools.wraps(wrapped)
    def _wrapper(*args, **kwargs):
        with _lock:
            return wrapped(*args, **kwargs)
    return _wrapper
567397
def method_missing(method_id, *args, &bl)
    @em_lock.synchronize{
      EventMachine.send method_id, *args, &bl
    }
  end
203318
function mutex($id,$func,$args=NULL) {
		if (!is_dir($tmp=$this->hive['TEMP']))
			mkdir($tmp,self::MODE,TRUE);
		// Use filesystem lock
		if (is_file($lock=$tmp.
			$this->get('SEED').'.'.$this->hash($id).'.lock') &&
			filemtime($lock)+ini_get('max_execution_time')<microtime(TRUE))
			// Stale lock
			@unlink($lock);
		while (!($handle=@fopen($lock,'x')) && !connection_aborted())
			usleep(mt_rand(0,100));
		$this->locks[$id]=$lock;
		$out=$this->call($func,$args);
		fclose($handle);
		@unlink($lock);
		unset($this->locks[$id]);
		return $out;
	}
295609
void lockForHandlingWork() {
        synchronized(m_lock) {
            assert m_running == false;
            m_running = true;
            m_readyOps = 0;
            m_readyOps = m_selectionKey.readyOps();      // runnable.run() doesn't accept parameters
        }
    }
311245
def synchronized(cls, obj=None):
        

        def get_key(f, o):
            if o is None:
                key = hash(f)
            else:
                key = hash(o)
            return key

        def get_lock(f, o):
            key = get_key(f, o)
            if key not in cls.lock_map:
                with cls.lock_map_lock:
                    if key not in cls.lock_map:
                        cls.lock_map[key] = _init_lock()
            return cls.lock_map[key]

        def wrap(f):
            @functools.wraps(f)
            def new_func(*args, **kw):
                with get_lock(f, obj):
                    return f(*args, **kw)

            return new_func

        return wrap
234517
def groom_thread_queues
      still_active = false
      @mutex.synchronize do
        @thread_name_to_queue.delete_if { |_, queue| false == queue.active? }
        still_active = false == @thread_name_to_queue.empty?
      end
      return still_active
    end
247010
public static final void acquireMultiple(long timeout, CMutex mutex[])
			throws RuntimeException {
		Arrays.sort(mutex, new CMutexComparator());
		for (int i = 0; i < mutex.length; i++) {
			try {
				mutex[i].acquire(timeout);
			} catch (RuntimeException re) {
				// release successfuly acquired mutex.
				for (int j = i - 1; j >= 0; j--) {
					if (mutex[j].isOwner()) {
						mutex[j].release();
					}
				}
				throw re;
			}
		}
	}
1041596
@Beta
    public static <T, R> Function<T, R> sf(final Object mutex, final Function<T, R> function) {
        N.checkArgNotNull(mutex, "mutex");
        N.checkArgNotNull(function, "function");

        return new Function<T, R>() {
            @Override
            public R apply(T t) {
                synchronized (mutex) {
                    return function.apply(t);
                }
            }
        };
    }
835724
private void lock() throws IOException {
		try {
			lock.lockInterruptibly();
		}
		catch (InterruptedException e) {
			Thread.currentThread().interrupt();
			throw new IOException("interrupted");
		}
	}