Understanding how Delay/Process work.

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

Understanding how Delay/Process work.

Mathieu Suen-2
Hi all,

I am trying to understand how process are working and made up a little script
but that does not work as I expected.

Here is the thing, I want to see if #forAt: added the process in the processor list at the given priority:


[ | i| i := 0. [(Delay forSeconds: 12) wait. i := i + 1. i printNl. true] whileTrue] forkAt: Processor highIOPriority
(Processor processesAt: Processor highIOPriority) waitingProcesses


But the second line return an empty list.
The process is running since in the transcript I can see the 1, 2, 3, ... output.
I am executing it in gst-browser I don't know if that change things.

Thanks for figuring it out.

        Mth




__________________________________________________
Do You Yahoo!?
En finir avec le spam? Yahoo! Mail vous offre la meilleure protection possible contre les messages non sollicités
http://mail.yahoo.fr Yahoo! Mail

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Understanding how Delay/Process work.

Paolo Bonzini-2
On 01/30/2011 11:46 PM, Mathieu Suen wrote:

> I am trying to understand how process are working and made up a little script
> but that does not work as I expected.
>
> Here is the thing, I want to see if #forAt: added the process in the processor list at the given priority:
>
>
> [ | i| i := 0. [(Delay forSeconds: 12) wait. i := i + 1. i printNl. true] whileTrue] forkAt: Processor highIOPriority
> (Processor processesAt: Processor highIOPriority) waitingProcesses
>
>
> But the second line return an empty list.

Because the processes returned by #processesAt: are only the _ready_
processes.  The process you're forking is not ready, it is waiting on a
semaphore owned by the Delay.

For example:

st> p :=
st>  [ | i| i := 0. [(Delay forSeconds: 12) wait. i := i + 1.
st>  i printNl. true] whileTrue] forkAt: Processor highIOPriority
Process(nil at highIOPriority, waiting on a semaphore)

st> "after some time"... Processor activeProcess yield
1
nil
st> Processor activeProcess yield
nil
st> p
Process(nil at highIOPriority, waiting on a semaphore)
st> p
Process(nil at highIOPriority, waiting on a semaphore)
st> Processor activeProcess yield
2
nil
st> p
Process(nil at highIOPriority, waiting on a semaphore)

You can see the behavior you want with a lower-priority process and
without a delay:

st> p := [ [Processor activeProcess yield] repeat] forkAt:
st>      Processor userBackgroundPriority
Process(nil at userBackgroundPriority, ready to run)
st> p name: 'test'
Process('test' at userBackgroundPriority, ready to run)
st> (Processor processesAt: p priority) waitingProcesses
(Process('test' at userBackgroundPriority, ready to run) )

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk