How does the UI update during this block?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How does the UI update during this block?

Sean P. DeNigris
Administrator
trues := 0.
[
        (1 to: 200000000) do: [ :e |
" (Delay forMilliseconds: 100) wait."
                        e \\ 1000000 == 0 ifTrue: [ trues := trues + 1 ] ].
        m delete ] fork.

I thought I would have to uncomment the #wait to give the UI a chance to update, but it works as is...
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: How does the UI update during this block?

Benjamin Van Ryseghem (Pharo)
Probably because the fork create a new process at priority 40, which is also the priority of the ui process.

So the processor dispatch between them I guess :)

Ben

On May 29, 2012, at 2:04 PM, Sean P. DeNigris wrote:

> trues := 0.
> [
> (1 to: 200000000) do: [ :e |
> " (Delay forMilliseconds: 100) wait."
> e \\ 1000000 == 0 ifTrue: [ trues := trues + 1 ] ].
> m delete ] fork.
>
> I thought I would have to uncomment the #wait to give the UI a chance to
> update, but it works as is...
>
> --
> View this message in context: http://forum.world.st/How-does-the-UI-update-during-this-block-tp4632333.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>


Reply | Threaded
Open this post in threaded view
|

Re: How does the UI update during this block?

Sean P. DeNigris
Administrator
Benjamin Van Ryseghem-2 wrote
Probably because the fork create a new process at priority 40, which is also the priority of the ui process.
So the processor dispatch between them I guess :)
I see where Morphic may give an opportunity to switch back to my block in #interCyclePause:, but when does the processor get a chance to switch out of my block? I tried debugging, but couldn't figure out a way to hook in before Morphic got control back (e.g. I put a haltOnce in Process>>resume, which was never called apparently; and putting a halt in the block itself just loops through the block repeatedly).

Here's the code accessing a global variable for logging:
  m := MyMorph new openInWorld. "MyMorph>>#step does - Messages add: 'step'."
  Messages := OrderedCollection new.
  trues := 0.
  [
        (1 to: 250000000) do: [ :e |
                "(Delay forMilliseconds: 100) wait."
                e \\ 5000000 == 0 ifTrue: [
                        Messages add: 'block - true'.
                        trues := trues + 1 ] ].
        m delete.
        WorldState addDeferredUIMessage: [Messages explore] ] forkAt: 30.

p.s. If I fork at 30, there is approximately a 1:1 interleaving of the world stepping and the ifTrue: part being executed. If I fork at 40 (UI priority), there is (very roughly) a 5:1 between the ifTrue: and world stepping, but it's very inconsistent.

I did not protect access to the global Messages, because I was worried the lock would change the process scheduling.
Cheers,
Sean