[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-smalltalk] Understanding how Delay/Process work.
From: |
Paolo Bonzini |
Subject: |
Re: [Help-smalltalk] Understanding how Delay/Process work. |
Date: |
Mon, 31 Jan 2011 08:49:57 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.7 |
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