Merge pull request #7927 from IgorNB/patch-1
SemaPhoreDemo double acquire fix
This commit is contained in:
commit
fdf812510f
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue