Merge pull request #7927 from IgorNB/patch-1

SemaPhoreDemo double acquire fix
This commit is contained in:
Loredana Crusoveanu
2019-10-10 20:48:16 +03:00
committed by GitHub

View File

@@ -12,9 +12,11 @@ public class SemaPhoreDemo {
System.out.println("Number of threads waiting to acquire: " + semaphore.getQueueLength()); System.out.println("Number of threads waiting to acquire: " + semaphore.getQueueLength());
if (semaphore.tryAcquire()) { if (semaphore.tryAcquire()) {
semaphore.acquire(); try {
// perform some critical operations // perform some critical operations
semaphore.release(); } finally {
semaphore.release();
}
} }
} }