Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 243855 - [WorkbenchLauncher] WorkbenchAdvisor.openWindows contains a data race
Summary: [WorkbenchLauncher] WorkbenchAdvisor.openWindows contains a data race
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2008-08-12 05:35 EDT by Marko Topolnik CLA
Modified: 2020-02-27 18:09 EST (History)
10 users (show)

See Also:


Attachments
Patch with the proposed solution (1.39 KB, patch)
2008-08-12 05:36 EDT, Marko Topolnik CLA
no flags Details | Diff
Suspended JVM after application hangs (68.68 KB, image/png)
2015-08-03 14:29 EDT, Peter Parapounsky CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marko Topolnik CLA 2008-08-12 05:35:33 EDT
Build ID: 3.5.0 -- current version at CVS

This is a code-inspection type of bug report. The code in WorkbenchAdvisor.openWindows uses a local array-variable initDone to signal the main thread that the worker thread is done. But the read and write operations to the initDone array element are not properly synchronized, creating a data race. My suggestion is to use a local holder class with a volatile boolean member.
Comment 1 Marko Topolnik CLA 2008-08-12 05:36:26 EDT
Created attachment 109768 [details]
Patch with the proposed solution
Comment 2 Paul Webster CLA 2008-08-12 12:51:48 EDT
What error can this "data race" produce in a boolean with only 2 threads involved?

This seems to me that it will either be true or false ... and the only reader of this variable is in the main thread.

PW
Comment 3 Marko Topolnik CLA 2008-08-13 03:06:05 EDT
(In reply to comment #2)

The main thread is not guaranteed to observe the write at the time the worker thread executes Display.wake(). Of course, this is not very serious because the worker thread is already about to die at that time. Unfortunately, now I don't think even introducing volatile will guarantee this. The compiler will still be allowed to reorder the execution so that Display.wake happens before the write. All that is guaranteed is that all the writes lexically preceeding the write to the volatile will be observed at the time the write itself is observed.

Still, this piece of code could easily be misunderstood because one is led to believe that the mentioned guarantee holds. In the future something else might be inserted here that is more relevant to program correctness and then the ordering may become a real issue, leading to nondeterministic bugs.
Comment 4 Marko Topolnik CLA 2008-08-14 03:21:38 EDT
(In reply to comment #2)

I checked once again and realized the following:

1. The write to result[0] is not guaranteed to be observed at the time it is read as a return value of openWindows so the method may legally return false even though the worker thread wrote true. The same is true for error[0]. At least these problems are definitely solved by the proposed patch as those writes precede the write to initDone[0].

2. If initDone[0] is read as false upon display.wake from the worker thread, it returns to sleep and will stay there until the next event, stalling further progress of the init routine for an indeterminate period. So this might after all be a more serious problem than it seemed.

Of course, as usual with multithreading issues, all this can be happily ignored because right now "it just works". But it's nice to at least know where the code stands with respect to proper thread synchronization.
Comment 5 Boris Bokowski CLA 2009-11-26 16:32:53 EST
Prakash is now responsible for watching bugs in the [WorkbenchLauncher] component area.
Comment 6 Peter Parapounsky CLA 2015-08-03 14:29:16 EDT
Created attachment 255599 [details]
Suspended JVM after application hangs
Comment 7 Peter Parapounsky CLA 2015-08-03 14:30:49 EDT
Hello, are there any plans to address this issue? 

It appears that our product that is based on Eclipse, runs into this on HP-UX(this is the only OS where this issue has been reported to occur so far).

Connecting to the JVM with a debugger and suspending the JVM when our application hangs, the debugger shows that the main thread sleeps at line:  "WorkbenchAdvisor.openWindows() line: 806" (see attached image "WorkbenchAdvisor.openWindows()")

This is reproducible on HP-UX about 40% of the time.

Here is the whole main thread stack trace: 

Java HotSpot(TM) Server VM[<machine_name>:8000] (Suspended)	
	Daemon Thread [Bundle File Closer] (Suspended)	
	Daemon Thread [[ThreadPool Manager] - Idle Thread] (Suspended)	
	Daemon Thread [[Timer] - Main Queue Handler] (Suspended)	
	Thread [Worker-JM] (Suspended)	
	Daemon Thread [Framework Event Dispatcher] (Suspended)	
	Daemon Thread [Start Level Event Dispatcher] (Suspended)	
	Daemon Thread [State Data Manager] (Suspended)	
	Thread [Framework Active Thread] (Suspended)	
	Daemon System Thread [Signal Dispatcher] (Suspended)	
	Daemon System Thread [Finalizer] (Suspended)	
	Daemon System Thread [Reference Handler] (Suspended)	
	Thread [main] (Suspended)	
		OS.Call(int, int, int, int) line: not available [native method]	
		Display.sleep() line: 4061	
		AgentUIWorkbenchAdvisor(WorkbenchAdvisor).openWindows() line: 806	
		Workbench$23.runWithException() line: 1493	
		Workbench$23(StartupThreading$StartupRunnable).run() line: 31	
		UISynchronizer(Synchronizer).syncExec(Runnable) line: 180	
		UISynchronizer.syncExec(Runnable) line: 150	
		Display.syncExec(Runnable) line: 4316	
		StartupThreading.runWithoutExceptions(StartupThreading$StartupRunnable) line: 94	
		Workbench.init() line: 1486	
		Workbench.runUI() line: 2587	
		Workbench.access$7(Workbench) line: 2476	
		Workbench$5.run() line: 593	
		Realm.runWithDefault(Realm, Runnable) line: 332	
		Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 550	
		PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 149	
		AgentUIApplication.launch(IApplicationContext, String[]) line: 387	
		AgentUIApplication.start(IApplicationContext) line: 87	
		EclipseAppHandle.run(Object) line: 196	
		EclipseAppLauncher.runApplication(Object) line: 110	
		EclipseAppLauncher.start(Object) line: 79	
		EclipseStarter.run(Object) line: 353	
		EclipseStarter.run(String[], Runnable) line: 180	
		NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
		NativeMethodAccessorImpl.invoke(Object, Object[]) line: 57	
		DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43	
		Method.invoke(Object, Object...) line: 606	
		Main.invokeFramework(String[], URL[]) line: 629	
		Main.basicRun(String[]) line: 584	
		Main.run(String[]) line: 1438	
		Main.main(String[]) line: 1414
Comment 8 Brian de Alwis CLA 2015-08-17 13:07:57 EDT
Wouldn't using an AtomicBoolean might be a better solution?
Comment 9 Andrey Loskutov CLA 2015-08-17 13:15:02 EDT
(In reply to Brian de Alwis from comment #8)
> Wouldn't using an AtomicBoolean might be a better solution?

It would. But anyone would be able to understand the code in that case :)
Comment 10 Lars Vogel CLA 2016-04-20 12:15:41 EDT
Mass move to 4.7 as M7 is approaching. Please move back in case you are planning to fix it for Neon.
Comment 11 Eclipse Genie CLA 2020-02-27 18:09:57 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.