638 |
|
} |
639 |
|
} |
640 |
|
|
641 |
+ |
/** |
642 |
+ |
* release(n) in one thread enables acquire(n) in another thread |
643 |
+ |
*/ |
644 |
+ |
public void testAcquireReleaseNInDifferentThreads_fair2() { |
645 |
+ |
final Semaphore s = new Semaphore(0, true); |
646 |
+ |
Thread t = new Thread(new Runnable() { |
647 |
+ |
public void run() { |
648 |
+ |
try { |
649 |
+ |
s.acquire(2); |
650 |
+ |
s.acquire(2); |
651 |
+ |
s.release(4); |
652 |
+ |
} catch(InterruptedException ie){ |
653 |
+ |
threadUnexpectedException(); |
654 |
+ |
} |
655 |
+ |
} |
656 |
+ |
}); |
657 |
+ |
try { |
658 |
+ |
t.start(); |
659 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
660 |
+ |
s.release(6); |
661 |
+ |
s.acquire(2); |
662 |
+ |
s.acquire(2); |
663 |
+ |
s.release(2); |
664 |
+ |
t.join(); |
665 |
+ |
} catch( InterruptedException e){ |
666 |
+ |
unexpectedException(); |
667 |
+ |
} |
668 |
+ |
} |
669 |
+ |
|
670 |
+ |
|
671 |
+ |
|
672 |
|
|
673 |
|
|
674 |
|
/** |