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
commit fdf812510f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

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();
}
} }
} }