ReentrantLock demo:signal&回报值; =>解锁?

时间:2017-08-19 17:59:05

标签: java concurrency reentrantlock

我正在尝试学习Java 8 Concurrent Programming和的基本概念 在这里的演示片段中无法理解使用返回解锁http://www.javatips.net/api/thinking-java-master/src/main/java/ch21concurrent/examples/ConditionBoundedBuffer.java

// BLOCKS-UNTIL: notEmpty
public  T take() throws InterruptedException {
    lock.lock();
    try {
        while (count == 0)
            notEmpty.await();
        T x = items[head];
        items[head] = null;
        if (++head == items.length)
            head = 0;
        --count;
        notFull.signal();
        return x;         // <<< RETURN without UNLOCK ? <<<
    } finally {
        lock.unlock();
    }
}

我读到了关于安全解锁的动机尝试/最终, 但是这里的&#39;返回x&#39; 是监视器proc。然后解锁 带着这个回归?

0 个答案:

没有答案
相关问题