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
[email protected]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

Reply via email to