Bug 265265 - SWT attempts to grab gtk Platform Lock in non-UI Thread
Summary: SWT attempts to grab gtk Platform Lock in non-UI Thread
Status: CLOSED WORKSFORME
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.5   Edit
Hardware: PC Linux-GTK
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Bogdan Gheorghe CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-18 03:41 EST by James Blackburn CLA
Modified: 2018-12-14 12:55 EST (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description James Blackburn CLA 2009-02-18 03:41:20 EST
Build ID: 3.5M5

Steps To Reproduce:
As per John A's comment bug 265028 comment 11, creating an Image on a non-UI thread (on Linux) attempts to lock the GTK SWT Platform Lock.  The non-UI Thread may be holding other locks at the time which allows deadlock between the non-UI thread and the main thread.

There's nothing on ImageDescriptor#createImage() that says Images must only be created on the UI thread. It looks like if Display.getDefault() == null it's initialised correctly in the Image constructor:

Resource(Device device) {
	if (device == null) device = Device.getDevice();
        ...
}

More information:
"Worker-5" prio=1 tid=0x0954c9d8 nid=0x17eb in Object.wait() [0x66593000..0x66593e50]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x727f88e8> (a org.eclipse.swt.internal.Lock)
        at java.lang.Object.wait(Unknown Source)
        at org.eclipse.swt.internal.Lock.lock(Lock.java:34)
        - locked <0x727f88e8> (a org.eclipse.swt.internal.Lock)
        at org.eclipse.swt.internal.gtk.OS.g_utf16_to_utf8(OS.java:2840)
        at org.eclipse.swt.internal.Converter.wcsToMbcs(Converter.java:63)
        at org.eclipse.swt.graphics.Image.initNative(Image.java:541)
        at org.eclipse.swt.graphics.Image.<init>(Image.java:531)
        at org.eclipse.jface.resource.URLImageDescriptor.createImage(URLImageDescriptor.java:162)
        at org.eclipse.jface.resource.ImageDescriptor.createImage(ImageDescriptor.java:227)
        at org.eclipse.ui.internal.registry.EditorDescriptor.getImageDescriptor(EditorDescriptor.java:294)
        - locked <0x727bf3d8> (a java.lang.Object)
        at org.eclipse.ui.internal.registry.EditorRegistry.getImageDescriptor(EditorRegistry.java:1423)
        at org.eclipse.ui.internal.ide.ContentTypeDecorator.decorate(ContentTypeDecorator.java:53)
Comment 1 James Blackburn CLA 2009-02-18 03:53:38 EST
bug 88255 (which was closed for lack of activity) shows the same problem Oleg encountered in Platform.

Should the (in-)ability to create Image & other SWT Resources on non-UI threads be Java Doc'd or possibly warn / throw an  Invalid Thread Access exception.

It's not clear that to users of the API that this will work on Windows but won't work on GKT Linux
Comment 2 James Blackburn CLA 2009-02-18 09:11:33 EST
(In reply to comment #1)
> Should the (in-)ability to create Image & other SWT Resources on non-UI threads
> be Java Doc'd or possibly warn / throw an  Invalid Thread Access exception?
> 
> It's not clear that to users of the API that this will work on Windows but
> won't work on GKT Linux

Or, given that this works unless clients have their own locks, perhaps the better solution would be for SWT GTK to release it's lock before calling client code.  It can always re-acquire the lock if the client calls back into it.

...
        at org.eclipse.jface.viewers.AbstractTreeViewer$4.treeExpanded(AbstractTreeViewer.java:1453)
        at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:126)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1156)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1180)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1165)
        at org.eclipse.swt.widgets.Tree.gtk_test_expand_row(Tree.java:2030)
        at org.eclipse.swt.widgets.Widget.windowProc(Widget.java:1570)
        at org.eclipse.swt.widgets.Display.windowProc(Display.java:4178)
        at org.eclipse.swt.internal.gtk.OS._gtk_main_do_event(Native Method)
        at org.eclipse.swt.internal.gtk.OS.gtk_main_do_event(OS.java:7534)
        at org.eclipse.swt.widgets.Display.eventProc(Display.java:1184)
...
Comment 3 Felipe Heidrich CLA 2009-02-18 10:58:08 EST
Silenio, don't we have a bug for this problem already ?
Comment 4 Xi Yan CLA 2018-11-30 17:11:56 EST
Is this still reproducible?
Comment 5 Xi Yan CLA 2018-12-14 12:55:06 EST
Closing this ticket now as there has been no response in awhile. Please reopen
it if you can reproduce the issue on GTK3.22/24 using SWT 4.10.