[cvs] / jsr166 / src / test / tck / AtomicBooleanTest.java Repository:
ViewVC logotype

Diff of /jsr166/src/test/tck/AtomicBooleanTest.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.12, Mon Nov 16 05:30:07 2009 UTC revision 1.13, Tue Nov 17 03:12:51 2009 UTC
# Line 79  Line 79 
79       * compareAndSet in one thread enables another waiting for value       * compareAndSet in one thread enables another waiting for value
80       * to succeed       * to succeed
81       */       */
82      public void testCompareAndSetInMultipleThreads() {      public void testCompareAndSetInMultipleThreads() throws Exception {
83          final AtomicBoolean ai = new AtomicBoolean(true);          final AtomicBoolean ai = new AtomicBoolean(true);
84          Thread t = new Thread(new Runnable() {          Thread t = new Thread(new Runnable() {
85                  public void run() {                  public void run() {
86                      while (!ai.compareAndSet(false, true)) Thread.yield();                      while (!ai.compareAndSet(false, true)) Thread.yield();
87                  }});                  }});
88          try {  
89              t.start();              t.start();
90              assertTrue(ai.compareAndSet(true, false));              assertTrue(ai.compareAndSet(true, false));
91              t.join(LONG_DELAY_MS);              t.join(LONG_DELAY_MS);
92              assertFalse(t.isAlive());              assertFalse(t.isAlive());
93          }          }
         catch (Exception e) {  
             unexpectedException();  
         }  
     }  
94    
95      /**      /**
96       * repeated weakCompareAndSet succeeds in changing value when equal       * repeated weakCompareAndSet succeeds in changing value when equal
# Line 124  Line 120 
120      /**      /**
121       * a deserialized serialized atomic holds same value       * a deserialized serialized atomic holds same value
122       */       */
123      public void testSerialization() {      public void testSerialization() throws Exception {
124          AtomicBoolean l = new AtomicBoolean();          AtomicBoolean l = new AtomicBoolean();
125    
         try {  
126              l.set(true);              l.set(true);
127              ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);              ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
128              ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));              ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
# Line 138  Line 133 
133              ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));              ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
134              AtomicBoolean r = (AtomicBoolean) in.readObject();              AtomicBoolean r = (AtomicBoolean) in.readObject();
135              assertEquals(l.get(), r.get());              assertEquals(l.get(), r.get());
         } catch (Exception e) {  
             e.printStackTrace();  
             unexpectedException();  
         }  
136      }      }
137    
138      /**      /**

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8