Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 40066

Summary: contention between debug console and SWT
Product: [Eclipse Project] Platform Reporter: Rafael Chaves <eclipse>
Component: DebugAssignee: Platform-Debug-Inbox <platform-debug-inbox>
Status: RESOLVED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: alex.blewitt, ben.grommes, Brian_Young, byron.hawkins, cocoakevin, eclipse, jeffmcaffer, kurt2002, mandrew, pascal, Tod_Creasey
Version: 2.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
test case (standard Java application). none

Description Rafael Chaves CLA 2003-07-14 18:07:39 EDT
Eclipse build i20030526

When running a SWT application from inside Eclipse, several SWT operations such
as getting the display for the first time will block if there is a thread
reading from the console.

I am not sure why is that, but I will attach a simple class that shows the problem.

In summary, there is two threads: one is reading from the console (System.in):

new Thread() {
  public void run() {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      while (true) {
        System.out.print("\n>");
        try {
          br.readLine();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  }
.start();

And after the previous thread is create, trying to get a display for the first
time (among other operations) wuill block.

An workaround is to change the loop above to use Reader.isReady() before trying
to read from the stream. If there is no data, wait for some time, and then try
again.
Comment 1 Rafael Chaves CLA 2003-07-14 18:08:23 EDT
Created attachment 5455 [details]
test case (standard Java application).
Comment 2 Steve Northover CLA 2003-07-14 18:22:33 EDT
SWT is not Eclipse.  Is this UI?  Sorry if it isn't.
Comment 3 Debbie Wilson CLA 2003-07-15 15:09:40 EDT
Tod, is UIJob the culprit here?
Comment 4 Tod Creasey CLA 2003-07-15 15:18:01 EDT
We don't do anything with the console - it looks like Rafaels application is 
blocking the UI Thread as the consolke is part of that. Moving to Debug for 
comment.
Comment 5 Darin Wright CLA 2003-07-15 16:09:33 EDT
When I debug this, the hang/delay is occurring in OS.GetDC(int) (which is a 
native). When I attempt to step over/into, things lock up. It is being called 
from Display.internal_new_GC(GC data). Doesn't seem to matter if I use java vs. 
javaw.
Comment 6 Darin Wright CLA 2003-07-15 16:12:10 EDT
I can get rid of the "lock up" by pressing enter in the console. Then, it locks 
up in Display.init(), in a call to OS.CreateWindowEx. Again, pressing ENTER 
makes allows the program to resume.
Comment 7 Darin Wright CLA 2003-07-15 16:15:39 EDT
The Eclipse console only "writes" to the input stream of programs when ENTER is 
pressed. I will investigate if this is the cause of the problem.
Comment 8 Darin Wright CLA 2003-07-15 16:39:57 EDT
Luc, could you see if the same problem exists on Linux?
Comment 9 Luc Bourlier CLA 2003-07-15 17:49:52 EDT
I don't get the problem on linux. When I launch the test case, I get the
following in the console without doing anything :

>Running
Got display
Comment 10 Darin Wright CLA 2004-04-13 11:01:42 EDT
Kevin, can you try this one on the Mac to see what happens.
Comment 11 Kevin Barnes CLA 2004-04-13 13:18:22 EDT
works fine on Mac, got the same output as Luc.
Comment 12 Darin Wright CLA 2004-05-25 10:54:39 EDT
Moving to SWT. Debug is not able to detemine that we are doing anything wrong, 
and it appears to be specific to Windows.
Comment 13 Veronika Irvine CLA 2004-05-27 14:45:37 EDT
Carolyn to investigate.
Comment 14 Rafael Chaves CLA 2005-01-18 11:56:52 EST
This happens to be a known issue:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4809647

It has nothing to do with SWT itself (it blocks System.loadLibrary), and is
triggered by the fact that the input stream of the launched VM is hooked by
debug (Process.getOutputStream()). I believe the fact Sun's class libraries are
licensed by other vendors is the reason why it can be reproduced on other VMs.

The bug report mentioned above provides a workaround. Moving back to debug for
consideration.
Comment 15 Darin Wright CLA 2005-01-19 08:48:30 EST
The workaround provided in the bug report 
(http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4809647) is a workaround 
that must be performed in the target (client) code. It's not something the 
Eclipse launcher can do.
Comment 16 Darin Wright CLA 2006-12-18 15:19:46 EST
*** Bug 53784 has been marked as a duplicate of this bug. ***
Comment 17 Darin Wright CLA 2007-02-08 09:37:03 EST
*** Bug 140838 has been marked as a duplicate of this bug. ***
Comment 18 Thomas Watson CLA 2007-05-10 09:42:36 EDT
*** Bug 186216 has been marked as a duplicate of this bug. ***
Comment 19 Thomas Watson CLA 2008-05-02 10:11:46 EDT
*** Bug 229400 has been marked as a duplicate of this bug. ***
Comment 20 Michael Rennie CLA 2008-10-15 13:06:43 EDT
*** Bug 250639 has been marked as a duplicate of this bug. ***