elt must be already locked (if it is not a thread.error
        exception will be raised)

        The recursive counter for elt is decremented and when it
        reaches zero the lock is released.
355257
def release(self, elt):
        
        self.lock.acquire()
        try:
            if elt not in self.locked:
                raise thread.error, "release unlocked lock for %s" % `elt`
            self.locked[elt][1] -= 1
            if not self.locked[elt][1]:
                del self.locked[elt]
        finally:
            self.lock.release()
554664
public synchronized void setQuietly(T t) {
        if ((ref != null) && (ref.get() == t)) return;  // If we've been told to set to the object we are already tracking, this is a no-op.
        this.unsetQuietly();
        ref = SharedReference.create(t, (Closeable)t);
    }
466510
private boolean init() throws IOException, CompoundNotFoundException {

		BufferedReader br = new BufferedReader(new FileReader(file));
		br.skip(sequenceStartIndex);
		String sequence = sequenceParser.getSequence(br, sequenceLength);
		setContents(sequence);
		br.close(); // close file to prevent too many being open

		return true;
	}
382282
def step(self):
        # type: () -> bool
        
        with self.__lock:
            self.__value -= 1
            if self.__value == 0:
                # All done
                self.__event.set()
                return True
            elif self.__value < 0:
                # Gone too far
                raise ValueError("The counter has gone below 0")

        return False
808135
private void lockWritersExclusive() {

        if (exclusiveLockOwner == Thread.currentThread()) {
            writers.decrementAndGet();
            return;
        }

        synchronized (this) {
            for (;;) {

                if (writers.compareAndSet(0, -1)) {
                    exclusiveLockOwner = Thread.currentThread();
                    return;
                }
            }
        }
    }
605448
def on_lock(self, widget, data=None):
        """"""
        path_list = None
        if self.view is not None:
            model, path_list = self.tree_view.get_selection().get_selected_rows()
        models = [self.list_store[path][self.MODEL_STORAGE_ID] for path in path_list] if path_list else []
        if models:
            if len(models) > 1:
                self._logger.warning("Please select only one element to be locked.")
            try:
                self.model.global_variable_manager.lock_variable(models[0])
            except AttributeError as e:
                self._logger.warning("The respective core element of {1}.list_store couldn't be locked. -> {0}"
                                  "".format(e, self.__class__.__name__))
            return True
        else:
            self._logger.warning("Please select an element to be locked.")
446095
private int dowait(boolean timed, long nanos)
        throws InterruptedException, BrokenBarrierException,
               TimeoutException {
        final ReentrantLock lock = this.lock;
        lock.lock();
        try {
            // The call to trip.await() further down will release the lock while this thread blocks.
            // The @RetainedLocalRef annotation ensures that "g" is still a valid reference after
            // returning from the trip.await() call.
            @RetainedLocalRef
            final Generation g = generation;

            if (g.broken)
                throw new BrokenBarrierException();

            if (Thread.interrupted()) {
                breakBarrier();
                throw new InterruptedException();
            }

            int index = --count;
            if (index == 0) {  // tripped
                boolean ranAction = false;
                try {
                    final Runnable command = barrierCommand;
                    if (command != null)
                        command.run();
                    ranAction = true;
                    nextGeneration();
                    return 0;
                } finally {
                    if (!ranAction)
                        breakBarrier();
                }
            }

            // loop until tripped, broken, interrupted, or timed out
            for (;;) {
                try {
                    if (!timed)
                        trip.await();
                    else if (nanos > 0L)
                        nanos = trip.awaitNanos(nanos);
                } catch (InterruptedException ie) {
                    if (g == generation && ! g.broken) {
                        breakBarrier();
                        throw ie;
                    } else {
                        // We're about to finish waiting even if we had not
                        // been interrupted, so this interrupt is deemed to
                        // "belong" to subsequent execution.
                        Thread.currentThread().interrupt();
                    }
                }

                if (g.broken)
                    throw new BrokenBarrierException();

                if (g != generation)
                    return index;

                if (timed && nanos <= 0L) {
                    breakBarrier();
                    throw new TimeoutException();
                }
            }
        } finally {
            lock.unlock();
        }
    }
506235
public final boolean synpred1_DRL5Lexer() {
		state.backtracking++;
		int start = input.mark();
		try {
			synpred1_DRL5Lexer_fragment(); // can never throw exception
		} catch (RecognitionException re) {
			System.err.println("impossible: "+re);
		}
		boolean success = !state.failed;
		input.rewind(start);
		state.backtracking--;
		state.failed=false;
		return success;
	}
508786
public void dereferenceControllable()
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "dereferenceControllable", tsm);
    
    streamSet = null;
    tsm = null;
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "dereferenceControllable"); 
  }
431250
private static CounterException rethrowAsCounterException(Throwable throwable) {
      //make it public if needed.
      if (throwable instanceof CounterException) {
         return (CounterException) throwable;
      } else if (throwable instanceof ExecutionException || throwable instanceof CompletionException) {
         return rethrowAsCounterException(throwable.getCause());
      } else {
         return new CounterException(throwable);
      }
   }
347157
public boolean tryLock() throws KeeperException {
        // 可能初始化的时候就失败了
        if (exception != null) {
            throw exception;
        }

        if (isOwner()) {// 锁重入
            return true;
        }

        acquireLock(null);

        if (exception != null) {
            unlock();
            throw exception;
        }

        if (interrupt != null) {
            unlock();
            Thread.currentThread().interrupt();
        }

        if (other != null) {
            unlock();
            throw new NestableRuntimeException(other);
        }

        return isOwner();
    }
80028
public void unlockCurrent(boolean redeliveryCountUnchanged) 
  throws SISessionUnavailableException, SISessionDroppedException,
         SIResourceException, SIConnectionLostException, 
         SIIncorrectCallException,
         SIErrorException, SIMPMessageNotLockedException
  {
    if (TraceComponent.isAnyTracingEnabled() && CoreSPILockedMessageEnumeration.tc.isEntryEnabled())
      SibTr.entry(CoreSPILockedMessageEnumeration.tc, "unlockCurrent", 
        new Object[] { new Integer(hashCode()), this, new Boolean(redeliveryCountUnchanged)});

    checkValidState("unlockCurrent");
          
    localConsumerPoint.checkNotClosed();  
    SIMPMessageNotLockedException notLockedException = null;
    
    synchronized(this)
    {  
      //check that there is a valid current message
      checkCurrentMessageAvailable(null);
      
      if(localConsumerPoint.getConsumerManager().getDestination().isOrdered())
      {
        unlockAll();
      }
      else
      {
        if(currentMsg != null)
        {
          // Remember that we've just unlocked this message, they may want to re-lock it
          // later
          currentUnlockedMessage = currentMsg;
  
          // We only actualy need to unlock it if it's actually in the MS
          if(currentMsg.isStored)
          {
            SIMPMessage msg = (SIMPMessage) (currentMsg.message);
            try
            {
              if (msg != null)
              {
                msg.unlockMsg(msg.getLockID(), null, !redeliveryCountUnchanged);
              }
            }
            catch (NotInMessageStore e)
            {
              // No FFDC code needed
              SibTr.exception(tc, e);
              // See defect 387591
              // We should only get this exception if the message was deleted via
              // the controllable objects i.e. the admin console. If we are here for
              // another reason that we have a real error.
              
              SibTr.error(tc, "INTERNAL_MESSAGING_ERROR_CWSIP0002",
                  new Object[] {
                  "com.ibm.ws.sib.processor.impl.JSLockedMessageEnumeration",
                  "1:445:1.8.1.10",
                  e });
                
              notLockedException =  new SIMPMessageNotLockedException(
                  nls.getFormattedMessage(
                      "INTERNAL_MESSAGING_ERROR_CWSIP0002",
                      new Object[] {
                          "com.ibm.ws.sib.processor.impl.JSLockedMessageEnumeration",
                          "1:453:1.8.1.10",
                          e },
                          null),
                          new SIMessageHandle[] {msg.getMessage().getMessageHandle()});
              notLockedException.initCause(e.getCause());
            }
            catch (MessageStoreException e)
            {
              // MessageStoreException shouldn't occur so FFDC.
              FFDCFilter.processException(
                e,
                "com.ibm.ws.sib.processor.impl.JSLockedMessageEnumeration.unlockCurrent",
                "1:465:1.8.1.10",
                this);
          
              SibTr.exception(tc, e);
              SibTr.error(tc, "INTERNAL_MESSAGING_ERROR_CWSIP0002",
                new Object[] {
                  "com.ibm.ws.sib.processor.impl.JSLockedMessageEnumeration",
                  "1:472:1.8.1.10",
                  e });
          
              if (TraceComponent.isAnyTracingEnabled() && CoreSPILockedMessageEnumeration.tc.isEntryEnabled())
                SibTr.exit(CoreSPILockedMessageEnumeration.tc, "unlockCurrent", e);
  
              throw new SIResourceException(
                nls.getFormattedMessage(
                  "INTERNAL_MESSAGING_ERROR_CWSIP0002",
                  new Object[] {
                    "com.ibm.ws.sib.processor.impl.JSLockedMessageEnumeration",
                    "1:483:1.8.1.10",
                    e },
                  null),
                e);
            }
          }
        }
      } // synchronized
  
          
      // Decrement the number of active messages for this consumer (outside the LME lock)
      localConsumerPoint.removeActiveMessages(1);
      
      if (notLockedException != null)
      {
        if (TraceComponent.isAnyTracingEnabled() && CoreSPILockedMessageEnumeration.tc.isEntryEnabled())
          SibTr.exit(CoreSPILockedMessageEnumeration.tc, "unlockCurrent", this);
        
        throw notLockedException;
      }
    }
    if (TraceComponent.isAnyTracingEnabled() && CoreSPILockedMessageEnumeration.tc.isEntryEnabled())
      SibTr.exit(CoreSPILockedMessageEnumeration.tc, "unlockCurrent", this);
  }
752824
public void lock() {
        Thread t = Thread.currentThread();
        if (t == owner.get()) { // if re-enter, increment the count.
            count++;
            return;
        }
        while (owner.compareAndSet(null, t)) {
        } //spin
    }
974000
def lock(self):
        ''''''

        component = self.component
        while True:
            if isinstance(
                    component,
                    smartcard.pcsc.PCSCCardConnection.PCSCCardConnection):
                hresult = SCardBeginTransaction(component.hcard)
                if 0 != hresult:
                    raise CardConnectionException(
                        'Failed to lock with SCardBeginTransaction: ' +
                        SCardGetErrorMessage(hresult))
                else:
                    # print('locked')
                    pass
                break
            if hasattr(component, 'component'):
                component = component.component
            else:
                break
71549
private double nextIteration(double correctionConstant) {
        // compute contribution of p(a|b_i) for each feature and the new
        // correction parameter
        double loglikelihood = 0.0;
        int numEvents = 0;
        int numCorrect = 0;

        int numberOfThreads = modelExpects.length;
        ExecutorService executor = Executors.newFixedThreadPool(numberOfThreads);
        int taskSize = numUniqueEvents / numberOfThreads;
        int leftOver = numUniqueEvents % numberOfThreads;

        List<Future<?>> futures = new ArrayList<>();

        for (int i = 0; i < numberOfThreads; i++) {
            int len = i == numberOfThreads - 1 ? taskSize + leftOver : taskSize;
            futures.add(executor.submit(new ModelExpactationComputeTask(i, i * taskSize, len)));
        }

        for (Future<?> future : futures) {
            ModelExpactationComputeTask finishedTask;
            try {
                finishedTask = (ModelExpactationComputeTask) future.get();
            } catch (InterruptedException e) {
                // TODO: We got interrupted, but that is currently not really supported!
                // For now we just print the exception and fail hard. We hopefully soon
                // handle this case properly!
                e.printStackTrace();
                throw new IllegalStateException("Interruption is not supported!", e);
            } catch (ExecutionException e) {
                // Only runtime exception can be thrown during training, if one was thrown
                // it should be re-thrown. That could for example be a NullPointerException
                // which is caused through a bug in our implementation.
                throw new RuntimeException("Exception during training: " + e.getMessage(), e);
            }

            // When they are done, retrieve the results ...
            numEvents += finishedTask.getNumEvents();
            numCorrect += finishedTask.getNumCorrect();
            loglikelihood += finishedTask.getLoglikelihood();
        }

        executor.shutdown();

        // merge the results of the two computations
        for (int pi = 0; pi < featNames.length; pi++) {
            int[] activeOutcomes = params[pi].getOutcomes();

            for (int aoi = 0; aoi < activeOutcomes.length; aoi++) {
                for (int i = 1; i < modelExpects.length; i++) {
                    modelExpects[0][pi].updateParameter(aoi, modelExpects[i][pi].getParameters()[aoi]);
                }
            }
        }

        // compute the new parameter values
        for (int pi = 0; pi < featNames.length; pi++) {
            double[] observed = observedExpects[pi].getParameters();
            double[] model = modelExpects[0][pi].getParameters();
            int[] activeOutcomes = params[pi].getOutcomes();
            for (int aoi = 0; aoi < activeOutcomes.length; aoi++) {
                if (useGaussianSmoothing) {
                    params[pi].updateParameter(aoi, gaussianUpdate(pi, aoi, correctionConstant));
                } else {
                    if (model[aoi] == 0) {
                        LOG.error("Model expects == 0 for " + featNames[pi] + " " + labels[aoi]);
                    }
                    params[pi].updateParameter(aoi, ((Math.log(observed[aoi]) - Math.log(model[aoi])) / correctionConstant));
                }

                for (MutableContext[] modelExpect : modelExpects) {
                    modelExpect[pi].setParameter(aoi, 0.0); // re-initialize to 0.0's
                }

            }
        }

        LOG.debug("loglikelihood = " + loglikelihood + "\taccuracy: " + ((double) numCorrect / numEvents) * 100);

        return loglikelihood;
    }
743457
public static void assertUnlocked(Object object, String name) {
        if (RUNTIME_ASSERTIONS) {
            if (Thread.holdsLock(object)) {
                throw new RuntimeAssertion("Recursive lock of %s", name);
            }
        }
    }
1155483
public synchronized void unlock() throws SevereMessageStoreException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "unlock", this);

        // If the subscription locks are down to zero then notify the threads waiting
        // for the subscriptionTable lock.
        synchronized (iMutex)
        {
            // If we are exclusively locked, then just return, as long as
            // the thread that is calling is the thread that holds the
            // exclusive lock.
            if (iExclusivelyLocked && iExclusiveLockHolder == Thread.currentThread())
            {
                if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "unlock");
                return;
            }

            // Decrement the lock count and notify the other threads if no
            // one holds the lock any more.
            if (--iLockCount == 0)
                notifyAll();

            if (iLockCount < 0)
            {
            	if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) SibTr.event(this, tc, "Unlock caused lock count to drop below zero!");
                if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "unlock");
                throw new SevereMessageStoreException("Unlock caused lock count to drop below zero!");
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "unlock");
    }