Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!newsflash.concordia.ca!sunqbc.risq.net!news.total.net!enews.sgi.com!news.sgi.com!mr.net!newshub.tc.umn.edu!fu-berlin.de!unlisys!blackbush.xlink.net!ins.net!heeg.de!hmm
From: hmm@heeg.de (Hans-Martin Mosner)
Subject: Re: [VW2.51] Checking termination of Process?
Message-ID: <DzMA18.ME7@heeg.de>
Sender: uucp@heeg.de
Organization: Georg Heeg Objektorientierte Systeme, Dortmund, FRG
X-Newsreader: TIN [version 1.2 PL2]
References: <32625DB0.4ADC@cs.tcd.ie> <540the$b6d@news00.btx.dtag.de>
Date: Mon, 21 Oct 1996 08:24:43 GMT
Lines: 49

Thilo Schmid (Thilo.KHK@t-online.de) wrote:
: Leon Hurst wrote:
: > 
: > How can one check for Process termination after sending it a terminate
: > message? It is meant to return self (the Process instance.)
: > 

: Non-Terminated processes are kept in the sole instance of
: ProcessScheduler, the global variable "Processor". Unfortunately, there
: is no protocol to check whether a process is still scheduled. But you
: can write one yourself. Look at "remove:ifAbsent" in ProcessScheduler to
: get an impression of how this must be done. If the Process is not
: scheduled in the processor, it is either terminated or never started. I
: guess you will not need to distinguish this.

Sorry, that's wrong. Processes waiting on semaphores are also non-terminated.
Processes in the Processor are just runnable. Here's a simple method that
does a termination test in VisualWorks 2.5 (probably applicable to 2.0, too):


'From VisualWorks(R), Release 2.5.1 of September 26, 1995 on October 21, 1996 at 9:24:42 am'!



!Process methodsFor: 'accessing'!

isTerminated
	"Return true if the receiver is a terminated process. Note: After the 
	#terminate message is sent to a process, it must have the 
	opportunity to actually do the termination. Therefore, 
		[] fork terminate isTerminated 
	does not return true, because the forked process did not have time 
	to execute the termination. In most other circumstances, the result 
	should be valid. For example: 
		([] forkAt: Processor userInterruptPriority) terminate isTerminated 
	returns true because it got the chance to do it."

	| finishedMethod sender |
	finishedMethod := self class compiledMethodAt: #finished.
	^suspendedContext method == finishedMethod
		or: 
			[sender := suspendedContext sender.
			sender notNil and: [sender method == finishedMethod]]! !

--
+--- Hans-Martin Mosner ---- Senior Smalltalk Guru :-) ---+
| These opinions are entirely ficticious.  Any similarity |
| to real opinions is purely coincidental and unintended. |
+--- <hmm@heeg.de> ------ URL:http://www.heeg.de/~hmm/ ---+
