Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Execution of various Runnables through asyncExec or syncExec(SWT, asyncExec, syncExec)
Execution of various Runnables through asyncExec or syncExec [message #684810] Thu, 16 June 2011 09:31 Go to next message
David Luengo is currently offline David LuengoFriend
Messages: 3
Registered: May 2011
Junior Member
A quick, but maybe obscure, question about the those methods of the Display class.

When we have various Threads asking the UI-Thread to execute Runnables (either via asyncExec or syncExec), can occur that a Runnable got interrupted and before it returns to execution another Runnable starts and ends?

I describe my situation. I have many Threads asking the UI-Thread to execute a Runnable that (among other things) adds elements to a list and i want to know if those Runnables will be executed "atomically" among them. This means that a specific Runnable cannot be started before other Runnable ends.

A snippet for this situation could be this.

public class UIThread {
    Display display;
    Shell shell;
    List<Object> list;

    // The Runnables to be executed by the UI-Thread because the other Threads ask
    // it via asyncExec(). Note that this Runnable access the list attribute of
    // the top class, in order to do it and not get a "Invalid Thread Access" it must
    // be done this way.
    private class RunnableToExec implements Runnable {
        @Override
        public void run() {
            <some work>
            list.add(new Object());
        }
    }

    // This class is just a Thread calling to the asyncExec to ask the UI-Thread
    // to execute a Runnable.
    private class ThreadCallingAsyncExec extends Thread {
        @Override
        public void run() {
            display.asyncExec(new RunnableToExec())
        }
    }

    // Entry point of the snippet.
    public static void main(String[] args) {
        ThreadCallingAsyncExec thread;

        // Create the Shell and Display.
        display = new Display()
        shell = new Shell(display);

        // Create the list where various Threads will be inserting something.
        list = new ArrayList<Object>();

        // Create a few Threads and run them.
        for (int i = 0; i < 10; i++) {
            thread = new ThreadCallingAsyncExec();
            thread.start();
        }
    }
}


This snippet was written on-the-fly, i don't know if it is well-written or (if so) if it works as i wanted, sorry about that.

What i want to know if is possible the next sequence:

- Each Thread exec asyncExec() (there are 10 Runnables queued).
- Runnable 1 starts to execute <some work>.
- Runnable 1 stops its execution (don't care why).
- Runnable 2 starts to execute.
- Runnable 2 finish.
- Runnable 1 returns to execution and executes list.add().
- Runnable 1 finish.
...

Here we have the situation that a Runnable starts to execute, then is interrupted and then another Runnable starts and ends before the previous Runnable finish. Can this situation occur or the Runnables are executed in (some kind of) order?.

Thanks for your wise!.
Re: Execution of various Runnables through asyncExec or syncExec [message #685816 is a reply to message #684810] Mon, 20 June 2011 09:43 Go to previous message
David Luengo is currently offline David LuengoFriend
Messages: 3
Registered: May 2011
Junior Member
I have been analyzing the problem and it seems that it cannot occur. The Display use an internal lock for executing runnables.
Previous Topic:Listing files in folder using webkit browser
Next Topic:Multi-Touch and gesture API: Rotate doesn't work correctly
Goto Forum:
  


Current Time: Sun Feb 23 14:53:13 GMT 2020

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

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

Back to the top