Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Is syncExec broken?
Is syncExec broken? [message #635702] Wed, 27 October 2010 18:24 Go to next message
Anders Baumann is currently offline Anders BaumannFriend
Messages: 55
Registered: July 2009
Member
This is a multi-part message in MIME format.

------=_NextPart_000_000C_01CB761D.4AB312D0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi All.
I have experience a rather strange behaviour in my application. I have =
the following piece of code which is executed in a Job thread:

System.out.println("1: " + Thread.currentThread());
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
System.out.println("2: " + Thread.currentThread());
}
});
System.out.println("3: " + Thread.currentThread());

When I run it I sometimes get the following output:

1: Thread[Worker-0,5,main]
3: Thread[Worker-0,5,main]
2: Thread[main,6,main]

So the line after the syncExec (3) is executed before the line inside =
the syncExec (2). How can that happen? According to the JavaDoc of =
syncExec : "The thread which calls this method is suspended until the =
runnable completes". Then how can 3 ever be called before 2? I am really =
puzzled. Can somebody please help me?

Thanks in advance,
Anders Baumann
------=_NextPart_000_000C_01CB761D.4AB312D0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META name=3DGENERATOR content=3D"MSHTML 8.00.6001.18975">
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT size=3D2 face=3DArial>Hi All.</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial>I have experience a rather strange =
behaviour in my=20
application. I have the following piece of code which is executed in a =
Job=20
thread:</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial><FONT size=3D2>&nbsp;&nbsp;&nbsp;</FONT><FONT =
size=3D2=20
face=3D"Courier New">&nbsp;&nbsp;System.out.println("1: " +=20
Thread.currentThread());<BR>&nbsp;&nbsp;&nbsp; =
Display.getDefault().syncExec(new=20
Runnable() {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
@Override<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void run()=20
{<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; System.out.println("2: =
"&nbsp; +=20
Thread.currentThread());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
}<BR>&nbsp;&nbsp;&nbsp; });<BR>&nbsp;&nbsp;&nbsp; System.out.println("3: =
"&nbsp;=20
+ Thread.currentThread());</FONT></FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>When I run it I sometimes get the =
following=20
output:</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3D"Courier New">1: =
Thread[Worker-0,5,main]<BR>3:=20
Thread[Worker-0,5,main]<BR>2: Thread[main,6,main]<BR></FONT></DIV>
<DIV>
<DIV><FONT size=3D2 face=3DArial>So the line after the syncExec (3) is =
executed=20
before the line inside the syncExec (2). How can that happen? According =
to the=20
JavaDoc of syncExec : "The thread which calls this method is suspended =
until the=20
runnable completes". Then how can 3 ever be called before 2? I am really =

puzzled. Can somebody please help me?</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Thanks in advance,</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial>Anders =
Baumann</FONT></DIV></DIV></BODY></HTML>

------=_NextPart_000_000C_01CB761D.4AB312D0--
Re: Is syncExec broken? [message #636209 is a reply to message #635702] Fri, 29 October 2010 16:03 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi Anders,

I've asked The Great Silenio about this and he's reasonably sure that it
should not be possible for this to happen with SWT's synchronizer which is
used by syncExec(). However if your case is happening in an RCP application
or eclipse plug-in in general then this default Synchronizer gets replaced
by the Eclipse platform, and it's possible that it is allowing this to
happen in some timing-dependent situations.

If you're able to create an swt-only snippet (ideal template:
http://www.eclipse.org/swt/faq.php#whatisasnippet ) that shows this
happening then please log a report with swt at
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Platform &component=SWT .
However I suspect that the swt-only case will always work, in which case you
should log a bug with UI at
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Platform &component=UI .

Grant


"Anders Baumann" <anb@maconomy.dk> wrote in message
news:ia9qhj$bhq$1@news.eclipse.org...
Hi All.
I have experience a rather strange behaviour in my application. I have the
following piece of code which is executed in a Job thread:

System.out.println("1: " + Thread.currentThread());
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
System.out.println("2: " + Thread.currentThread());
}
});
System.out.println("3: " + Thread.currentThread());

When I run it I sometimes get the following output:

1: Thread[Worker-0,5,main]
3: Thread[Worker-0,5,main]
2: Thread[main,6,main]

So the line after the syncExec (3) is executed before the line inside the
syncExec (2). How can that happen? According to the JavaDoc of syncExec :
"The thread which calls this method is suspended until the runnable
completes". Then how can 3 ever be called before 2? I am really puzzled. Can
somebody please help me?

Thanks in advance,
Anders Baumann
Previous Topic:Context menu problems in Windows 7 and Linux
Next Topic:Linux GTK hanging in an RCP Application for java 6
Goto Forum:
  


Current Time: Thu Dec 05 15:50:14 GMT 2019

Powered by FUDForum. Page generated in 0.02913 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top