Igor,<div><br></div><div> take a look at the VisualWorks finalization code. There a process is spawned to run each finalizer, and there is a throttling mechanism to ensure that the system does not create a flood of processes when lots of objects are to be finalized. Instead, a new finalization process is created only when the previous one starts to run. A new finalizer process is created when the previous one starts because, due to errors, the previous one may never finish, but it will always start.</div>
<div><br></div><div><div>outerFinalizationLoop</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>"Forks a process that will send every finalizable object (weak</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> indexable class or Ephemeron) on the finalization queue the</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> mourn message. Separate processes are used to fetch</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> finalizable objects and to finalize them so that if errors occur</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> in finalization they don't stop the finalization mechanism</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> altogether. This method uses the ratchet semaphore to arrange</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> that each new processes is only forked after the previous</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> process has made progess. Hence this avoids creating many</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> new processes that can't run because they have lower priority</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> than the finalization process, and in the process possibly</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> running out of memory."</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>| theBereaved ratchet |</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>ratchet := Semaphore new.</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>[FinalizationSemaphore wait.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>theBereaved := [self fetchFromFinalizationQueue]</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                                        </span>on: self queueOverflowSignal</div><div><span class="Apple-tab-span" style="white-space:pre">                                                        </span>do: [:ex | ex return: #overflow].</div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>theBereaved == nil ifFalse: </div><div><span class="Apple-tab-span" style="white-space:pre">                </span>[[ratchet signal.</div><div><span class="Apple-tab-span" style="white-space:pre">                </span> self innerFinalizationLoopWith: theBereaved]</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>forkAt: Processor lowIOPriority.</div><div><span class="Apple-tab-span" style="white-space:pre">                </span> ratchet wait]] repeat</div><div><br></div><div>
<div>innerFinalizationLoopWith: initialValue </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>"Sends every finalizable object (weak indexable class or Ephemeron) on the finalization queue the mourn message."</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>initialValue == #overflow ifTrue:</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>[^self handleFinalizationQueueOverflow].</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>[| theBereaved |</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> theBereaved := initialValue.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> [theBereaved mourn.</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> (theBereaved := self fetchFromFinalizationQueue) ~~ nil] whileTrue]</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>on: self queueOverflowSignal</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>do: [:ex | </div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>self handleFinalizationQueueOverflow.</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>ex return]</div>
</div><div><br></div><div><br></div>(there are details like the use of handleFinalizationQueueOverflow that you can ignore)</div><div><br></div><div>HTH</div><div>Eliot</div><div><br><div class="gmail_quote">On Mon, Oct 11, 2010 at 1:17 PM, Igor Stasenko <span dir="ltr"><<a href="mailto:siguctua@gmail.com">siguctua@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">On 11 October 2010 22:49, Schwab,Wilhelm K <<a href="mailto:bschwab@anest.ufl.edu">bschwab@anest.ufl.edu</a>> wrote:<br>
> Sig,<br>
><br>
</div><div class="im">> The most important words in there are "critical section." Carry on :)<br>
><br>
<br>
</div>Oh, please. This is not too hard to code.<br>
<br>
My mind rolling around following choice(s) (there may be others i don't see).<br>
What would be a proper way to handle error during #finalize.<br>
<br>
[ executor finalize ] on: Error do: [:ex |<br>
self handleFinalizationError: ex "where self is registry"<br>
].<br>
<br>
or:<br>
<br>
[ executor finalize ] on: Error do: [:ex |<br>
executor handleFinalizationError: ex<br>
].<br>
<br>
<br>
of course, i should catch this error in test, so i can verify that:<br>
<br>
a) test is get notified upon synthetically made error<br>
b) no matter what i do inside error handler (up to 'Processor<br>
activeProcess terminate'), a finalization process continues working<br>
(or restarts without losing remainder of executors).<br>
<br>
<br>
Also, i used #ensure: and #ifCurtailed: but i tend to forget where<br>
they are applicable and how.<br>
So, little help in this regard will be wellcome.<br>
<div><div></div><div class="h5"><br>
> Bill<br>
><br>
--<br>
Best regards,<br>
Igor Stasenko AKA sig.<br>
<br>
</div></div></blockquote></div><br></div>