Skip to content

Instantly share code, notes, and snippets.

@mabdi
Created December 2, 2020 14:19
Show Gist options
  • Save mabdi/273ad119790de2792b7167849c4cfb11 to your computer and use it in GitHub Desktop.
Save mabdi/273ad119790de2792b7167849c4cfb11 to your computer and use it in GitHub Desktop.
[| tag delay x exec_pr semaphorExecutor executor watcher |
x := 0.
tag := self.
delay := 5 seconds asDelay.
exec_pr := Processor activePriority - 10.
self traceCr: Time now print24.
semaphorExecutor := Semaphore new.
executor := [
[[ delay wait.
self traceCr: 'Im done at: ', Processor activePriority asString.
semaphorExecutor signal] ensure: [ "evaluate the receiver"
executor := nil.
delay delaySemaphore signal ]]
on: TimedOut
do: [ :qq | self traceCr: 'I am killed'. semaphorExecutor signal ] ] newProcess.
executor priority: exec_pr .
watcher := [ |goOn|
self traceCr: 'Watcher started'.
goOn := true.
[ goOn ] whileTrue:
[
x := x + 1.
self traceCr: 'Checking on ', x asString.
x >= 3 ifTrue: [
self traceCr: 'Killing executor'.
executor
ifNotNil: [ executor signalException: (TimedOut new tag: tag) ].
goOn := false.
] ifFalse: [
1 seconds wait]
]] newProcess.
watcher priority: executor priority + 1.
watcher resume.
executor resume.
semaphorExecutor wait.
self traceCr: 'main resumed at: ', Processor activePriority asString.
self traceCr: Time now print24.] forkAt: Processor activePriority - 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment