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

Bug 335400

Summary: [Workbench] AbstractUIPlugin imposes bogus restrictions on thread access to public API
Product: [Eclipse Project] Platform Reporter: Randy Hudson <hudsonr>
Component: UIAssignee: Platform UI Triaged <platform-ui-triaged>
Status: CLOSED WONTFIX QA Contact:
Severity: enhancement    
Priority: P5 CC: daniel_megert, francisu, pwebster, remy.suen
Version: 3.6   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug

Description Randy Hudson CLA 2011-01-25 18:29:37 EST
Methods like AbstractUIPlugin#getImageRegistry call createImageRegistry, which has the unnecessary restriction that there either be a Display associated with the current thread, or that the platform workbench be running.  There is no reason to be on the display thread to construct images.  If there is no current display, createImageRegistry and similar methods should call Display#getDefault()
Comment 1 Oleg Besedin CLA 2011-01-26 10:53:23 EST
Please see the entry in the Eclipse help under
 Platform Plug-in Developer Guide > 
   Programmer's Guide > 
     Standard Widget Toolkit >
       Threading issues

Unless specified, all processing is assumed to be done on the UI thread.
Comment 2 Randy Hudson CLA 2011-01-26 15:06:09 EST
Again, that entry is invalid. Would you like me to open a separate bugzilla to have the SWT doc fixed?
Comment 3 Oleg Besedin CLA 2011-01-26 16:06:06 EST
Sorry, I forgot to mark this as invalid. This is essentially the same as the bug 335399.
Comment 4 Randy Hudson CLA 2011-01-27 17:21:34 EST
getImageRegistry actually lets you call it from a background thread (if the workbench is running) or from the UI thread.  Yet this method isn't thread-safe, which means two or more copies of the registry could be in use.  One thread could also receive the registry created by another, which might not have been completely initialized.
Comment 5 Dani Megert CLA 2011-01-28 03:25:02 EST
(In reply to comment #4)
> getImageRegistry actually lets you call it from a background thread
Well, only because you can do it doesn't mean it is allowed and supported. In general, the *.ui.* code is supposed to run in the UI thread unless specified otherwise. Having said that, the image registry is a good example where it would be handy to call it in the non-UI thread, especially because it's often used when a bundle gets started and this can be triggered from a non-UI thread.
Comment 6 Francis Upton IV CLA 2011-01-28 03:29:01 EST
(In reply to comment #5)
> he *.ui.* code is supposed to run in the UI thread unless specified
> otherwise. Having said that, the image registry is a good example where it
> would be handy to call it in the non-UI thread, especially because it's often
> used when a bundle gets started and this can be triggered from a non-UI thread.
I think this is related to some issue that I was working on a year or two ago about allowing images to be obtained though some API. I don't remember the exact issue, but I remember there were possible problems with deadlock in the startup related to requiring the images to be created on the UI thread. When I get some time I will try to find the relevant bug report, but I think relaxing this restriction might have helped that.
Comment 7 Oleg Besedin CLA 2011-01-28 10:15:05 EST
This bug and the bug 335399 are about the same thing. Which one of those bugs can be closed as duplicate?
Comment 8 Randy Hudson CLA 2011-01-28 12:20:21 EST
335399 Is about the lack thread safety.  Once getImageRegistry can be called from background worker threads safely, then this bug is about the current requirement that the workbench be running to do so.

I realize that calling Display#getDefault() is dangerous since it might create a Display.  So either SWT should provide a similar method that only returns the "default" display iff it already exists, or PlatformUI could allow clients to manage the Display "lifecycle", so that PlatformUI can have a Display even when a workbench is not needed.
Comment 9 Randy Hudson CLA 2011-01-28 12:22:24 EST
(In reply to comment #6)
> I think this is related to some issue that I was working on a year or two ago
> about allowing images to be obtained though some API. I don't remember the
> exact issue, but I remember there were possible problems with deadlock in the
> startup related to requiring the images to be created on the UI thread. When I
> get some time I will try to find the relevant bug report, but I think relaxing
> this restriction might have helped that.

Indeed, if you need an Image and are forced to do a syncExec to get it, the unnecessary use of syncExec can cause deadlock on some SWT platforms (read GTK).
Comment 10 Lars Vogel CLA 2019-09-24 13:50:15 EDT
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.

If you have further information on the current state of the bug, please add it. 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.