Acquire a read lock. Several threads can hold this typeof lock.
        It is exclusive with write locks.
547627
def acquire_read(self):
        
        self.monitor.acquire()
        while self.rwlock < 0 or self.writers_waiting:
            self.readers_ok.wait()
        self.rwlock += 1
        self.monitor.release()
577824
public synchronized int read(byte b[], int off, int len) throws IOException
    {
        int avail=_avail-_pos;
        if (avail <=0)
        {
            fill();
            avail=_avail-_pos;
        }

        if (avail <=0)
            len=-1;
        else
        {
            len=(avail < len) ? avail : len;
            System.arraycopy(_buf,_pos,b,off,len);
            _pos +=len;
        }
        
        return len;
    }
854316
private ClientRWLock getBlockLock(long blockId) {
    // Loop until we either find the block lock in the mLocks map, or successfully acquire a new
    // block lock from the lock pool.
    while (true) {
      ClientRWLock blockLock;
      // Check whether a lock has already been allocated for the block id.
      synchronized (mSharedMapsLock) {
        blockLock = mLocks.get(blockId);
        if (blockLock != null) {
          blockLock.addReference();
          return blockLock;
        }
      }
      // Since a block lock hasn't already been allocated, try to acquire a new one from the pool.
      // Acquire the lock outside the synchronized section because #acquire might need to block.
      // We shouldn't wait indefinitely in acquire because the another lock for this block could be
      // allocated to another thread, in which case we could just use that lock.
      blockLock = mLockPool.acquire(1, TimeUnit.SECONDS);
      if (blockLock != null) {
        synchronized (mSharedMapsLock) {
          // Check if someone else acquired a block lock for blockId while we were acquiring one.
          if (mLocks.containsKey(blockId)) {
            mLockPool.release(blockLock);
            blockLock = mLocks.get(blockId);
          } else {
            mLocks.put(blockId, blockLock);
          }
          blockLock.addReference();
          return blockLock;
        }
      }
    }
  }
936
public final boolean tryLockForRead(L locker) {
        int state = mState;
        if (state >= 0) { // no write lock is held
            if (isReadWriteFirst() || isReadLockHeld(locker)) {
                do {
                    if (incrementReadLocks(state)) {
                        adjustReadLockCount(locker, 1);
                        return true;
                    }
                    // keep looping on CAS failure if a reader or upgrader mucked with the state
                } while ((state = mState) >= 0);
            }
        } else if (mOwner == locker) {
            // keep looping on CAS failure if a reader or upgrader mucked with the state
            while (!incrementReadLocks(state)) {
                state = mState;
            }
            adjustReadLockCount(locker, 1);
            return true;
        }
        return false;
    }
1258250
public final void unlockFromRead(L locker) {
        adjustReadLockCount(locker, -1);

        int readLocks;
        while ((readLocks = decrementReadLocks(mState)) < 0) {}

        if (readLocks == 0) {
            Node h = mRWHead;
            if (h != null && h.mWaitStatus != 0) {
                unparkReadWriteSuccessor(h);
            }
        }
    }
734624
def release_readlock(lockdir_name):
    
    # Make sure the lock still exists before deleting it
    if os.path.exists(lockdir_name) and os.path.isdir(lockdir_name):
        os.rmdir(lockdir_name)
245010
public synchronized boolean lock() throws KeeperException, InterruptedException {
        if (isClosed()) {
            return false;
        }
        ensurePathExists(dir);

        return (Boolean) retryOperation(zop);
    }
1189433
def acquire_write(self):
        
        self.monitor.acquire()
        while self.rwlock != 0:
            self.writers_waiting += 1
            self.writers_ok.wait()
            self.writers_waiting -= 1
        self.rwlock = -1
        self.monitor.release()
1204742
public void openReadWrite(ReadStreamOld is, WriteStreamOld os) throws IOException
  {
    getWrappedPath().openReadWrite(is, os);
  }
1252402
public int read() throws IOException {
        synchronized (lock) {
            ensureOpen();
            for (;;) {
                if (nextChar >= nChars) {
                    fill();
                    if (nextChar >= nChars)
                        return -1;
                }
                if (skipLF) {
                    skipLF = false;
                    if (cb[nextChar] == '\n') {
                        nextChar++;
                        continue;
                    }
                }
                return cb[nextChar++];
            }
        }
    }
1110290
def acquire_lock
      return true if @lock_handle
      begin
        @lock_handle = File.open(lock_file_path, File::RDWR | File::CREAT)
        raise StandardError.new('Already locked') unless @lock_handle.flock(File::LOCK_EX | File::LOCK_NB)
        @lock_handle.rewind
        @lock_handle.truncate 0
        @stat_handle = File.open(status_file_path, File::RDWR | File::CREAT)
        raise StandardError.new('Failed to open status') unless @stat_handle
        @stat_handle.rewind
        @stat_handle.truncate 0
      rescue
        if @stat_handle
          @stat_handle.close rescue nil
        end
        if @lock_handle
          @lock_handle.flock(File::LOCK_UN) rescue nil
          @lock_handle.close rescue nil
        end
        @stat_handle = nil
        @lock_handle = nil
      end
      !!@lock_handle
    end
1188622
public <EXTYPE extends Exception> void readLockedThrowing (@Nonnull final IThrowingRunnable <EXTYPE> aRunnable) throws EXTYPE
  {
    readLock ().lock ();
    try
    {
      aRunnable.run ();
    }
    finally
    {
      readLock ().unlock ();
    }
  }
324932
private function read()
    {
        $this->lock();

        $data = '';

        rewind($this->handle);

        $data = trim(stream_get_contents($this->handle));

        if ($data !== '') {
            $this->data = unserialize($data);
            $data = null;
        }

        flock($this->handle, LOCK_UN);

        $this->iterator = new \ArrayIterator($this->data);
    }
1064835
def release(self):
        
        self.monitor.acquire()
        if self.rwlock < 0:
            self.rwlock = 0
        else:
            self.rwlock -= 1
        wake_writers = self.writers_waiting and self.rwlock == 0
        wake_readers = self.writers_waiting == 0
        self.monitor.release()
        if wake_writers:
            self.writers_ok.acquire()
            self.writers_ok.notify()
            self.writers_ok.release()
        elif wake_readers:
            self.readers_ok.acquire()
            self.readers_ok.notifyAll()
            self.readers_ok.release()
1202957
public void startRead() {
		SynchronizationPoint<NoException> sp;
		synchronized (this) {
			if (!writer) {
				// nobody is writing, we can read
				readers++;
				return;
			}
			// if someone is writing, we need to wait
			if (readerWaiting == null)
				readerWaiting = new SynchronizationPoint<NoException>();
			sp = readerWaiting;
			readers++;
		}
		sp.block(0);
	}
468640
public void openReadWrite(ReadStreamOld is, WriteStreamOld os) throws IOException
  {
    clearStatusCache();

    StreamImpl impl = openReadWriteImpl();
    //impl.setPath(this);

    os.init(impl);
    is.init(impl);
  }
281278
def release(self):
        
        me = threading.currentThread()
        self.__condition.acquire()
        try:
            if self.__writer is me:
                self.__writer_lock_count -= 1
                if self.__writer_lock_count == 0:
                    self.__writer = None
                    self.__condition.notifyAll()
            elif me in self.__readers:
                self.__readers[me] -= 1
                if self.__readers[me] == 0:
                    del self.__readers[me]
                    if not self.__readers:
                        self.__condition.notifyAll()
            else:
                raise thread.error, "release unlocked lock"
        finally:
            self.__condition.release()