Cover Yarda's failed attempt to fix mutex with a test.
1.1 --- a/openide.util/test/unit/src/org/openide/util/MutexTest.java Fri May 12 23:08:01 2006 +0000
1.2 +++ b/openide.util/test/unit/src/org/openide/util/MutexTest.java Wed May 17 16:51:11 2006 +0000
1.3 @@ -565,14 +565,15 @@
1.4 A.start();
1.5 tickX1.waitOn();
1.6 // A reached point X
1.7 -
1.8 +
1.9 B.start();
1.10 tickX3.waitOn();
1.11 // B reached point X, unlocked A so in would block on lock(L)
1.12
1.13 C.start();
1.14 - // C is blocking in leave/privilegedEnter
1.15 -
1.16 + Thread.sleep(100); // wait for C to perform exitReadAccess (can't
1.17 + // tick as it will block in case of failure...)
1.18 +
1.19 tickX1.tick();
1.20 // push B, everything should finish after this
1.21
1.22 @@ -869,6 +870,48 @@
1.23
1.24 new ReadWriteChecking ("None at the end", Boolean.FALSE, Boolean.FALSE).run ();
1.25 }
1.26 +
1.27 + // [pnejedly:] There was an attempt to fix Starvation68106 by allowing read
1.28 + // enter while Mutex is currently in CHAIN mode, but that's wrong, as it can
1.29 + // be CHAIN/W (write granted, readers waiting). Let's cover this with a test.
1.30 + public void testReaderCannotEnterWriteChainedMutex() throws Exception {
1.31 + final Mutex.Privileged PR = new Mutex.Privileged();
1.32 + final Mutex M = new Mutex(PR);
1.33 + final boolean[] done = new boolean[2];
1.34 +
1.35 + final Ticker tickX1 = new Ticker();
1.36 + final Ticker tickX2 = new Ticker();
1.37 + final Ticker tickX3 = new Ticker();
1.38 +
1.39 + PR.enterWriteAccess();
1.40 +
1.41 + Thread A = new Thread("A") { public void run() {
1.42 + PR.enterReadAccess();
1.43 + done[0] = true;
1.44 + PR.exitReadAccess();
1.45 + }};
1.46 +
1.47 + Thread B = new Thread("B") { public void run() {
1.48 + PR.enterReadAccess();
1.49 + done[1] = true;
1.50 + PR.exitReadAccess();
1.51 + }};
1.52 +
1.53 + A.start();
1.54 + Thread.sleep(100); // wait for A to chain in M
1.55 +
1.56 + B.start();
1.57 + Thread.sleep(100);; // B should chain as well
1.58 +
1.59 + assertFalse ("B should chain-wait", done[1]);
1.60 +
1.61 + // final cleanup and consistency check:
1.62 + PR.exitWriteAccess();
1.63 + A.join(1000);
1.64 + B.join(1000);
1.65 + assertTrue("A finished after unblocking M", done[0]);
1.66 + assertTrue("B finished after unblocking M", done[1]);
1.67 + }
1.68
1.69 public void testIsReadOrWriteForEventMutex () throws Exception {
1.70 class Test implements Runnable {