[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.platform.swt] Re: aSyncExec behavior

Spencer Stejskal wrote:

does Display.aSyncExec(Runnable) only run its runnable when the display thread returns to the event loop?

more specifically if the spawned thread below in the nonBlockingMethod gets to LINE Y before the display thread gets to LINE X is the potential there for the
display thread to run the runnable in the asyncExec call before the display thead finishes the someMethod invocation or will it wait until its back into the display loop?

There is only one event loop thread per Display. The thread can only be processing one event at a time. If the event loop thread has called your someMethod() method like your comments indicate, it can't get to any other events until after your someMethod() returns. This means that the event loop can't process the Runnable you create in line Y until after your someMethod() returns.



private class SomeClass
{
        private List list = new ArrayList();

public void someMethod()
{
long pid = nonBlockingMethod(display); {called from the display thread, dont worry about where the display is retrieved from}
//do some more work, maybe long maybe short
LINE X list.add(pid);
}

private long nonBlockingMethod(final Display display)
{
long pid = generatePID();
Thread t = new Thread(new Runnable(){
public void run()
{
//do some work, maybe long maybe short
LINE Y display.asyncExec(new Runnable(){
public void run()
{
if(list.contains(pid))
{
//do one thing
}
else
{
//do another thing
}
}
});
}
});
t.start();
return pid;
}
}