Bug 429363 - [Workbench] init thread sometimes completes between initDone and display.sleep()
Summary: [Workbench] init thread sometimes completes between initDone and display.sleep()
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.4   Edit
Hardware: PC Linux-GTK
: P3 critical (vote)
Target Milestone: 4.4 RC3   Edit
Assignee: Paul Webster CLA
QA Contact: Paul Webster CLA
URL:
Whiteboard:
Keywords:
: 434967 435693 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-02-28 16:17 EST by Paul Webster CLA
Modified: 2021-06-29 14:33 EDT (History)
6 users (show)

See Also:
emoffatt: review+
daniel.rolka: review+


Attachments
RCP app that sleeps forever (16.24 KB, application/zip)
2014-02-28 16:17 EST, Paul Webster CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Webster CLA 2014-02-28 16:17:21 EST
Created attachment 240417 [details]
RCP app that sleeps forever

I have code that calls display.wake() from another thread while the main loop is in a display.sleep().  It doesn't wake up.

while (true) {
	if (!display.readAndDispatch()) {
		if (initDone[0])
			break;
	System.err.println("sleep"); //$NON-NLS-1$
		display.sleep();
	System.err.println("get up"); //$NON-NLS-1$
	}
	
}

With syserr logs I see the "sleep" and then I see the "wake" from the other thread display.wake() ... but I don't see the "get up"

You an reproduce by importing the attached plugin, opening the plugin.xml, and Launch as an eclipse app.

It stays asleep in org.eclipse.ui.application.WorkbenchAdvisor.openWindows().

PW
Comment 1 Niraj Modi CLA 2014-03-14 05:35:21 EDT
Hi Paul,
Not able to reproduce this issue with the the attached plugin project.
Also we don't see the display.sleep()/display.wake() calls in this code.
Comment 2 Paul Webster CLA 2014-03-14 06:04:38 EDT
The wake/sleep calls that cause the problem for me are at org.eclipse.ui.application.WorkbenchAdvisor.openWindows()

I'll re-test it with M6.

PW
Comment 3 Paul Webster CLA 2014-03-28 09:53:53 EDT
I can reproduce it easily on 4.4.0.I20140325-0830.  But I believe it's related to thread timing, not display.

PW
Comment 4 Paul Webster CLA 2014-03-28 09:54:34 EDT
Changing the thread finally to below fixes the problem:
initDone[0] = true;
yield();
display.wake();

PW
Comment 6 Paul Webster CLA 2014-04-29 11:36:00 EDT
I can still reproduce the problem.

PW
Comment 7 Paul Webster CLA 2014-04-30 10:13:02 EDT
This only happens to me with one of our test apps, so I'm deferring it.

PW
Comment 8 Paul Webster CLA 2014-05-24 09:19:28 EDT
*** Bug 435693 has been marked as a duplicate of this bug. ***
Comment 9 Paul Webster CLA 2014-05-24 09:35:26 EDT
(In reply to Paul Webster from comment #4)
> initDone[0] = true;
> yield();
> display.wake();

from org.eclipse.ui.application.WorkbenchAdvisor.openWindows()
while (true) {
	if (!display.readAndDispatch()) {
		if (initDone[0])
			break;
		display.sleep();
	}
	
}


even with a yield before the display.wake(), the above loop manages to hang in simple RCP cases.

PW
Comment 10 Paul Webster CLA 2014-05-24 09:43:16 EDT
https://git.eclipse.org/r/27235

I tried making the initDone volatile so that it must be checked by each thread.  That worked for one invocation (I delete the workspace on each run) but then it went back to hanging.

PW
Comment 11 Paul Webster CLA 2014-05-24 10:00:39 EDT
https://git.eclipse.org/r/27236

Here's a change that seems to fix my problem consistently.

The init thread spawns another thread that also has a display.wake() in it.  If we get into the scenario where our yield();display.wake(); is not enough, the second display wake will fix it.  If the original code works, the display wake is  no-op.

I don't like this fix.

PW
Comment 12 Paul Webster CLA 2014-05-24 10:19:24 EDT
https://git.eclipse.org/r/27238

This approach is hacky, deliberately adding 5 ms between the initDone=true and the display.wake().  But it worked on fixing my problem and without adding another (hacky) thread to the system.  That makes it much more predictable.

PW
Comment 13 Paul Webster CLA 2014-05-28 11:56:02 EDT
Eric, can you please review comment #12

PW
Comment 15 Paul Webster CLA 2014-06-12 09:16:44 EDT
*** Bug 434967 has been marked as a duplicate of this bug. ***
Comment 16 Eclipse Genie CLA 2021-06-29 14:33:42 EDT
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.ui/+/182619