help-smalltalk
[Top][All Lists]
Advanced

[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:35:06 +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 11:38 AM, Holger Hans Peter Freyther wrote:
$ a := [[(Delay forSeconds: 300) wait] ensure: ['Terminated' printNl]] fork.
$ a terminate
Process(nil at userSchedulingPriority, ready to run)
$ a terminate
'Terminated'
Process(nil at userSchedulingPriority, terminated)

Not a bug, it won't happen when you run the program outside the REPL (or if the REPL let processes run in the background.

To work around such sticky processes I have decided to use a [proc
isTerminated] whileFalse: [proc terminate] construct.

It's enough to do

proc terminate. [proc isTerminated] whileFalse: [Processor yield]

For example:

st> Eval [
   proc := [[(Delay forSeconds: 300) wait]
      ensure: ['Terminated' printNl]] fork.
   proc terminate.
   [proc isTerminated] whileFalse: [Processor yield].
   proc
]
'Terminated'
Process(nil at userSchedulingPriority, terminated)

The reason is that termination is a non-trivial operation which involves sending the ProcessBeingTerminated exception. It also may cause a context switch.

Paolo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]