enhanced unwind handling upon process termination
This commit is contained in:
@ -170,10 +170,20 @@
|
||||
^self atLevel: Log.INFO log: message.
|
||||
}
|
||||
|
||||
#method log: message and: message2
|
||||
{
|
||||
^self atLevel: Log.INFO log: message and: message2.
|
||||
}
|
||||
|
||||
#method logNl: message
|
||||
{
|
||||
^self atLevel: Log.INFO logNl: message.
|
||||
}
|
||||
|
||||
#method logNl: message and: message2
|
||||
{
|
||||
^self atLevel: Log.INFO logNl: message and: message2.
|
||||
}
|
||||
}
|
||||
|
||||
#class Namespace(Set)
|
||||
|
@ -150,6 +150,7 @@
|
||||
## -------------------------------------------------------------------
|
||||
|
||||
| ctx stop |
|
||||
|
||||
ctx := self.
|
||||
stop := false.
|
||||
[stop] whileFalse: [
|
||||
|
@ -43,9 +43,38 @@
|
||||
self primitiveFailed
|
||||
}
|
||||
|
||||
#method _suspend
|
||||
{
|
||||
<primitive: #_process_suspend>
|
||||
self primitiveFailed
|
||||
}
|
||||
|
||||
#method terminate
|
||||
{
|
||||
##search from the top contextof the process down to intial_contextand find ensure blocks and execute them.
|
||||
## if a different process calls 'terminate' on a process,
|
||||
## the ensureblock is not executed in the context of the
|
||||
## process being terminated, but in the context of terminatig process.
|
||||
##
|
||||
## 1) process termianted by another process
|
||||
## p := [
|
||||
## [ 1 to: 10000 by: 1 do: [:ex | System logNl: i asString] ] ensure: [System logNl: 'ensured....']
|
||||
## ] newProcess.
|
||||
## p resume.
|
||||
## p terminate.
|
||||
##
|
||||
## 2) process terminated by itself
|
||||
## p := [
|
||||
## [ Processor activeProcess terminate. ] ensure: [System logNl: 'ensured....']
|
||||
## ] newProcess.
|
||||
## p resume.
|
||||
## p terminate.
|
||||
## ----------------------------------------------------------------------------------------------------------
|
||||
## the process must be frozen first. while unwinding is performed,
|
||||
## the process must not be scheduled.
|
||||
## ----------------------------------------------------------------------------------------------------------
|
||||
|
||||
(Processor activeProcess ~~ self) ifTrue: [ self _suspend ].
|
||||
self.current_context unwindTo: self.initial_context return: nil.
|
||||
^self _terminate
|
||||
}
|
||||
|
@ -80,7 +80,8 @@
|
||||
v1 := [
|
||||
[
|
||||
[
|
||||
1 to: 10000 by: 1 do: [:i | System logNl: i asString. Processor sleepFor: 5. ]
|
||||
##1 to: 20000 by: 1 do: [:i | System logNl: i asString. "Processor sleepFor: 1." ]
|
||||
Processor activeProcess terminate.
|
||||
] ensure: [ System logNl: '<<<PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP>>>' ].
|
||||
|
||||
] ensure: [ System logNl: '<<--------------------->>' ].
|
||||
@ -88,9 +89,10 @@
|
||||
|
||||
System logNl: 'RESUMING v1'.
|
||||
v1 resume.
|
||||
Processor sleepFor: 1.
|
||||
v1 terminate.
|
||||
|
||||
##[
|
||||
##[
|
||||
## [ Processor activeProcess terminate. ] ensure: [System logNl: '<<<PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP>>>' ].
|
||||
##] ensure: [ System logNl: '<<--------------------->>' ].
|
||||
|
||||
|
Reference in New Issue
Block a user