@@ -0,0 +1,1012 @@
+package com.github.mottox.taomp.concurrent;%0A%0Aimport java.util.concurrent.locks.Condition;%0Aimport java.util.concurrent.locks.Lock;%0Aimport java.util.concurrent.locks.ReentrantLock;%0A%0A/**%0A * %E4%B8%80%E7%A7%8D%E7%AE%80%E5%8D%95%E7%9A%84%E4%BF%A1%E5%8F%B7%E9%87%8F%E5%AE%9E%E7%8E%B0%E3%80%82%0A */%0Apublic class Semaphore %7B%0A%0A    private final int capacity;%0A%0A    private volatile int state;%0A%0A    private Lock lock;%0A%0A    private Condition condition;%0A%0A    public Semaphore(int capacity) %7B%0A        this.capacity = capacity;%0A        state = 0;%0A        lock = new ReentrantLock();%0A        condition = lock.newCondition();%0A    %7D%0A%0A    public void acquire() %7B%0A        lock.lock();%0A        try %7B%0A            while (state == capacity) %7B%0A                condition.await();%0A            %7D%0A            state++;%0A        %7D catch (InterruptedException e) %7B%0A            // empty%0A        %7D finally %7B%0A            lock.unlock();%0A        %7D%0A    %7D%0A%0A    public void release() %7B%0A        lock.lock();%0A        try %7B%0A            state--;%0A            condition.signalAll();%0A        %7D finally %7B%0A            lock.unlock();%0A        %7D%0A    %7D%0A%7D%0A

Implement Semaphore.java