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

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

Reply via email to