Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4041790

Race condition in hide/show under Motif


    • Subcomponent:
    • CPU:
    • OS:


      [03/27/97 cskim]

      AWT components are marked visible internally before peer.show()
      completes, this introduces a race condition.

      When trying to pop up a window for an arbitrary amount of time, by
      show()ing, sleep()ing, then hide()ing, but on a heavily loaded (and
      slow) system, occassionally the sleep completes before the component is
      actually visible (at the peer level) and the hide gets thrown away...

      -- testcase
      Depending on the machine this sometimes happens right away and
      sometimes some combination works. I have tried this on both the
      X86 Solaris and Sparc Solaris.

      Modified the code several times and there is definitely a timing
      issue here. The situation will arise when I change the sleep
      value between 1000 - 10000 range and the output from the test is
      that the frame window stays up while following message appears:

      Begin Test!
      Frame now visible: true
      Frame not Visible!
      Frame not Showing!
      End of Test!

      -- application testcase
      import java.awt.Frame;
      import java.awt.Label;
      // Demonstrate race condition between a components hide() and show() methods
      // caused by a discrepency between the components internal notion of its own
      // visibility and that of it's peer.
      public class TestHide {
          public static void main( String [] argvp ) throws InterruptedException {
              System.out.println ( "Begin Test!" );

              Frame f = new Frame( "Test Frame" );
              f.add( "Center", new Label( "...Testing..." ) );
              // Uncommenting this line will "fix" it
      // Thread.sleep ( 1000 );
              while ( !f.isShowing() )
                  System.out.print (".");

              f.hide(); // Peer never disappears...
      // Thread.sleep ( 1000 );

              if ( f.isVisible() )
                  System.out.println ( "Frame Visible!" );
                  System.out.println ( "Frame not Visible!" );

              if ( f.isShowing() )
                  System.out.println ( "Frame Showing!" );
                  System.out.println ( "Frame not Showing!" );

              System.out.println ( "End of Test!" );

      There definitely seems to be some timing problem. When I hold
      down another icon as I execute the application the problem seems
      to occur right away and consistently. However when I just let
      it run, the problem doesn't seem to occur. I was able to eliminate
      delays which initially introduced the problem to where without any
      delays and holding down another icon when executing the java app
      the problem surfaced again. The problem can be more easily created
      with delay however.




            • Assignee:
              duke J. Duke (Inactive)
            • Votes:
              0 Vote for this issue
              2 Start watching this issue


              • Created: