[Sugar-devel] Is there a way to purposefully do synchronous GUI updates?
James Cameron
quozl at laptop.org
Tue Aug 21 02:32:16 EDT 2012
First, learn that on a single processor system, only one thread
actually executes at a given time, so if you think you have more than
one thread of execution, you're wrong and you really only have one.
As soon as you expand the time for sampling, yes, more than one
thread, or process, may execute.
In this situation, threads are an abstraction which distorts reality.
On Tue, Aug 21, 2012 at 11:33:55AM +0530, Ajay Garg wrote:
> Thanks James for the reply.
>
>
> On Tue, Aug 21, 2012 at 3:47 AM, James Cameron <quozl at laptop.org> wrote:
>
> On Tue, Aug 21, 2012 at 12:11:13AM +0530, Ajay Garg wrote:
> > So, is there a way to have the code always in-order; in other words,
> > have the GUI updates absolutely synchronous?
>
> No, not without waiting for the update to complete, and if you do
> this, the code runs very slowly.
>
> (When there is only one CPU, only one process can execute on it at a
> time. The updates are placed in a pipeline to the display, and the
> display process runs them as soon as it is practical to do so. If
> your process does not release the CPU, then your process will likely
> continue executing until it hits something that will cause it to
> release. It is better to be specific and use idle_add to release.)
>
>
> Right.
>
> Now, from what I believe, that there is just one "main" thread, that is
> responsible for running the "normal, backend" code, and the same "main" thread
> does the GUI updates (of the events present in the display pipeline), when it
> has nothing more to do with the "normal, backend" code.
>
> This also means, that doing something like
>
> main_thread.wait()
>
> would be idiotic, as that would stall the GUI updates as well.
I don't understand what you would hope to achieve by calling .wait().
> So, does there exist a method, that could cause doing the GUI updates in a
> different (other than the "main" thread) ?
> If yes, that would solve the issue, as the following would then be feasible ::
>
> <main thread> logic statement 1
> <main thread> spawn a new thread, and pass the GUI-update event to
> it |
> <main thread> "joins" on the new
> thread |
>
> | anywhere in this interval, the new thread performs the GUI update
>
> |
>
> |
>
> new thread terminates
> <main thread> logic statement 2
>
>
>
> At first, it seems that the "<main thread> spawn a new thread, and pass the
> GUI-update event to it" step is trivial.
> However, the thing to note that in a default python configuration, all GUI
> update events are scheduled in the context of the main thread.
>
> So, only if the GUI update events could be scheduled to be processed in a
> custom thread - that would be awesome !!!
>
>
> Please let me know if any such method exists :)
No, I don't think so. It is an event loop implementation only.
For more information, google "Threads Considered Harmful", and check
out John Ousterhout's paper "Why Threads Are A Bad Idea (for most
purposes)."
--
James Cameron
http://quozl.linux.org.au/
More information about the Sugar-devel
mailing list