[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-smalltalk] Delay in a Process and sending #terminate
From: |
Paolo Bonzini |
Subject: |
Re: [Help-smalltalk] Delay in a Process and sending #terminate |
Date: |
Sat, 18 Dec 2010 13:42:20 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.12) Gecko/20101103 Fedora/1.0-0.33.b2pre.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.6 |
On 12/18/2010 12:31 PM, Holger Hans Peter Freyther wrote:
A:
[
[ ] ensure: [
mutex critical: ['Sometimes never entered' printNl.
allProcesses remove:
Processor activeProcess].
]
] fork
B:
mutex criticial: [allProcesses do: [:each | each terminate ]].
I think sometimes this statement will not executed when the process is being
terminated. What I am trying to do is to have a cleanup handler for processes.
E.g. to make a process remove itself from a list of processes.
This should work. It may be that you're not waiting long enough.
mutex := Semaphore forMutualExclusion.
allProcesses := IdentitySet new.
i := 0.
p := [ :x |
[ (Delay forMilliseconds: x) wait ] ensure: [
mutex critical: [i := i + 1.
allProcesses remove: Processor activeProcess].
]
].
1000 timesRepeat: [
(allProcesses add: (p newProcessWith: {Random between: 300 and:
1000}))
resume ].
(Delay forMilliseconds: 450) wait.
mutex critical: [allProcesses do: [:each | each terminate ]].
(Delay forMilliseconds: 2000) wait.
i printNl.
If you change the final "2000" you indeed get an output that is less
than 1000.
That said, this reproduces the other bug in Delay, so thanks. :)
Paolo