SemaPhoreDemo double acquire fix

tryAcquire() already acquires a permit, if one is available (no need to call acquire() after it)
This commit is contained in:
IgorNB 2019-10-02 12:52:46 +03:00 committed by GitHub
parent e1a6b9f63b
commit f3537acf6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,7 +12,6 @@ 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();
// perform some critical operations // perform some critical operations
semaphore.release(); semaphore.release();
} }