author | Claus Gittinger <cg@exept.de> |
Thu, 27 Jun 2019 16:34:40 +0200 | |
changeset 24379 | 852be153b0ec |
parent 24238 | 51ace3995288 |
child 24775 | 76c608493514 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1992 by Claus Gittinger |
159 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
5377 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
17407 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
1 | 16 |
Link subclass:#Process |
19292 | 17 |
instanceVariableNames:'id lookupActivations lookupDisabled prio state startBlock name |
18 |
restartable interruptActions exitActions suspendSemaphore |
|
19 |
singleStepping emergencySignalHandler suspendActions creatorId |
|
20 |
processGroupId interruptsDisabled priorityRange |
|
21324 | 21 |
exceptionHandlerSet processType environment startTimestamp' |
16562 | 22 |
classVariableNames:'TerminateSignal RestartSignal CaughtSignals' |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
23 |
poolDictionaries:'' |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
24 |
category:'Kernel-Processes' |
1 | 25 |
! |
26 |
||
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
27 |
!Process class methodsFor:'documentation'! |
88 | 28 |
|
29 |
copyright |
|
30 |
" |
|
31 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
159 | 32 |
All Rights Reserved |
88 | 33 |
|
34 |
This software is furnished under a license and may be used |
|
35 |
only in accordance with the terms of that license and with the |
|
36 |
inclusion of the above copyright notice. This software may not |
|
37 |
be provided or otherwise made available to, or used by, any |
|
38 |
other person. No title to or ownership of the software is |
|
39 |
hereby transferred. |
|
40 |
" |
|
41 |
! |
|
42 |
||
43 |
documentation |
|
44 |
" |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
45 |
WARNING: |
19969 | 46 |
the offsets of the instance variables lookupActivations and lookupDisabled are known in the VM |
47 |
do not remove them, and do not insert/remove instance variables before them |
|
18189
e06ab6591712
hardcoding instvar offsets is VERY BAD (fix for Jan's lookup bug)
Claus Gittinger <cg@exept.de>
parents:
17544
diff
changeset
|
48 |
|
14722 | 49 |
Instances of Process represent lightweight smalltalk processes |
88 | 50 |
(i.e. threads). These all run in a shared smalltalk/X address space, |
93 | 51 |
and can thus access and communicate via any objects. |
52 |
Do not confuse these with (heavy-weight) unix processes, which are |
|
53 |
created differently, and do NOT run in the same address space. |
|
54 |
Also notice, that heavy-weight process creation takes much longer. |
|
55 |
(see OperatingSystemclass>>fork). |
|
56 |
||
21777 | 57 |
Smalltalk processes do not necessarily need to be implemented as native |
4646
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
58 |
threads - it may, but the actual implementation depends on the underlying |
21777 | 59 |
OS's features. However, even if implemented as native thread, the ST/X |
4646
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
60 |
kernel makes certain, that only one thread executes at a time (with certain, |
20230 | 61 |
well-defined exceptions). The reason is that the required locking in the |
4646
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
62 |
runtime system would make things slower in most cases. |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
63 |
|
202 | 64 |
Processes are typically created by sending #fork or #forkAt: to a block; |
65 |
the block creates a new process, defines itself as its startBlock, |
|
66 |
and (optionally) tells the Processor about the new process. |
|
67 |
||
4646
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
68 |
Scheduling is done by Processor, which is the sole instance of ProcessorScheduler. |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
69 |
In ST/X, the scheduling algorithms are fully implemented (and visible) on the |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
70 |
smalltalk level - beside the threadSwitch primitive, there is virtually no VM |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
71 |
support (i.e. it can be easily changed). |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
72 |
|
93 | 73 |
|
202 | 74 |
Processes can be terminated either soft or via a hardTerminate. |
217 | 75 |
|
202 | 76 |
A soft terminate (see Process>>terminate) will raise a TerminationSignal |
14722 | 77 |
in the process, which can be handled by the process. |
78 |
If no other handler was specified, the processes own handler |
|
79 |
(see Process>>start) will catch the signal and terminate the process. |
|
217 | 80 |
During this signal processing, normal unwind processing takes place, |
14722 | 81 |
this means that with a soft terminate, all valueOnUnwind:/valueNowOrOnUnwind: |
217 | 82 |
cleanup blocks are evaluated. |
202 | 83 |
(so a process which has set up those blocks correctly does not have to |
84 |
care especially about cleanup in case of termination). |
|
2689 | 85 |
Other than that, the TerminateSignal can be caught for special cleanup or |
217 | 86 |
even to make the process continue execution. |
4415
dff1649c072c
resume the process when terminated.
Claus Gittinger <cg@exept.de>
parents:
4002
diff
changeset
|
87 |
If the process is suspended at termination time, it will be resumed |
14722 | 88 |
in order to perform its cleanup actions (i.e. the cleanup is always |
4415
dff1649c072c
resume the process when terminated.
Claus Gittinger <cg@exept.de>
parents:
4002
diff
changeset
|
89 |
done in the context of the terminating process itself). |
202 | 90 |
|
91 |
A hard terminate (Process>>terminateNoSignal) will NOT do all of the above, |
|
92 |
but quickly (and without any cleanup) terminate the process. |
|
93 |
The debugger offers a quickTerminate option on its popupMenu for |
|
94 |
situations, when soft termination fails. (for example, if some error was |
|
95 |
coded into a handler or unwind block). |
|
96 |
||
20777 | 97 |
Leaving the processes startBlock has the same effect as a soft-terminate |
4415
dff1649c072c
resume the process when terminated.
Claus Gittinger <cg@exept.de>
parents:
4002
diff
changeset
|
98 |
(i.e. there is no need to send an explicit terminate). |
dff1649c072c
resume the process when terminated.
Claus Gittinger <cg@exept.de>
parents:
4002
diff
changeset
|
99 |
|
14722 | 100 |
Notice: |
19969 | 101 |
in Smalltalk/X, processes are gone, when an image is restarted; |
21777 | 102 |
this means that you have to take care of process re-creation yourself. |
19969 | 103 |
Usually, this is done by depending on ObjectMemory, recreating the |
104 |
process(es) when the #returnFromSnapshot-change notifiction arrives. |
|
105 |
||
106 |
All views (actually windowGroups) recreate their window process |
|
107 |
on image-restart. You have to do so manually for your own processes. |
|
93 | 108 |
|
109 |
A later version will allow specification of automatic restart, but |
|
13563 | 110 |
that's not yet implemented. However, even when implemented, restartable processes |
217 | 111 |
will be recreated to restart from the beginning. It will not be possible to |
112 |
automatically continue a processes execution where it left off. |
|
113 |
This is a consequence of the portable implementation of ST/X, since in order to |
|
14722 | 114 |
implement process continuation, the machines stack had to be preserved and |
115 |
recreated. Although this is possible to do (and actually not too complicated), |
|
116 |
this has not been implemented, since the machines stack layout is highly machine/compiler |
|
375 | 117 |
dependent, thus leading to much bigger porting effort of ST/X (which conflicts |
118 |
with ST/X's design goal of being highly portable). |
|
217 | 119 |
|
120 |
Process synchronization: |
|
19969 | 121 |
Synchronization with cooperating processes is supported as usual, |
122 |
via Semaphores (see Semaphore, Delay, SharedQueue etc.) |
|
123 |
||
124 |
With uncooperative processes, only synchronization on suspend |
|
125 |
and termination is possible: |
|
126 |
any other process can wait for a process to suspend or terminate. |
|
127 |
This waiting is implemented by using suspendSemaphore and exitBlocks |
|
128 |
(where an exitSemaphore is signalled). |
|
129 |
See waitUntilSuspended / waitUntilTerminated. |
|
130 |
||
131 |
Implementation note: |
|
132 |
for historic and compatibility reasons, Process is a subclass of Link, |
|
133 |
which means, that instances are directly usable as nodes in a linkedList. |
|
21777 | 134 |
However, this also means that processes can only be elements of a single LinkedList. |
19969 | 135 |
This is somewhat dangerous, as unknowledgable programmers may unwillingly break the |
136 |
scheduler, by placing a process onto another linked list. |
|
137 |
Therefore, we plan to change this in the future. |
|
21777 | 138 |
|
3784 | 139 |
Process states: |
19969 | 140 |
#dead process has (been) terminated; |
21777 | 141 |
the process instance has no underlying |
19969 | 142 |
thread. |
143 |
||
144 |
#run the process is willing to run, |
|
145 |
but not active (i.e. another higher prio |
|
146 |
process is currently executing) |
|
147 |
||
148 |
#active the process is the current process |
|
149 |
(there is only one) |
|
150 |
||
151 |
#ioWait waiting on some io-related semaphore |
|
152 |
(typically in #readWait / #writeWait) |
|
153 |
||
154 |
#eventWait waiting on some GUI event |
|
155 |
||
156 |
#timeWait waiting on a timer-related semaphore |
|
157 |
||
158 |
#wait waiting on some (other) semaphore |
|
159 |
||
160 |
#suspended stopped from execution; however, an interrupt |
|
161 |
will return it into the run state. |
|
162 |
||
163 |
#stopped stopped from execution; an interrupt will |
|
164 |
NOT return it into the run state (for debugging) |
|
165 |
||
166 |
#debug debugger sitting on top of the processes |
|
167 |
stack. |
|
3784 | 168 |
|
169 |
Win32 only: |
|
170 |
||
19969 | 171 |
#osWait waiting on an OS-API call to finish. |
172 |
can be interrupted, terminated and aborted |
|
21777 | 173 |
(i.e. the usual context actions are possible). |
19969 | 174 |
|
175 |
#halted thread was caught while in a blocking API call |
|
176 |
or primitive endless loop and has been halted by |
|
177 |
the scheduler. |
|
178 |
Can only be resumed or hard-terminated - abort |
|
179 |
or soft terminate or unwind actions are not possible. |
|
180 |
(due to win32 limitations) |
|
3784 | 181 |
|
182 |
||
1273 | 183 |
[Instance variables:] |
93 | 184 |
|
19969 | 185 |
id <SmallInteger> a unique process-id |
186 |
||
187 |
creatorId <SmallInteger> the id of the process that |
|
188 |
created me (useful for debugging |
|
189 |
or monitoring). |
|
190 |
||
191 |
processGroupId usually the id of the creator, |
|
192 |
unless the process detached from |
|
193 |
the group and became a groupLeader. |
|
194 |
Groups can be easily terminated |
|
195 |
as a whole. |
|
196 |
Group leaders have a groupId of nil. |
|
197 |
A groupId of 0 (zero) marks a system |
|
198 |
process; these do not prevent a standAlone |
|
199 |
app from exiting. |
|
200 |
||
201 |
prio <SmallInteger> the processes priority |
|
202 |
||
203 |
priorityRange <Interval> the processes dynamic priority range |
|
204 |
(or nil) |
|
205 |
||
206 |
state <Symbol> the processes state |
|
207 |
(for process-monitor) |
|
208 |
||
209 |
startBlock <Block> the startup-block (the one that forked) |
|
210 |
||
211 |
name <String-or-nil> the processes name (if any) |
|
212 |
(for process-monitor) |
|
213 |
||
214 |
suspendSemaphore <Semaphore> triggered when suspend (if nonNil) |
|
215 |
||
216 |
restartable <Boolean> is restartable; if true, the process |
|
217 |
will be restarted when an image is |
|
218 |
restarted. Otherwise, it remains dead. |
|
219 |
Running processes cannot be continued |
|
220 |
at the point where leftOff after an |
|
221 |
image-restart. |
|
222 |
||
223 |
interruptActions <Collection> interrupt actions as defined by interruptWith:, |
|
224 |
performed at interrupt time |
|
225 |
||
226 |
exitActions <Collection of Block> |
|
227 |
additional cleanup actions to perform |
|
228 |
on termination (if nonEmpty) |
|
229 |
||
230 |
emergencySignalHandler <Block> can be used for per-process |
|
231 |
emergency signal handling |
|
232 |
||
233 |
interruptsDisabled <Boolean> flag if interrupts (as installed |
|
234 |
via #interruptWith:) are currently |
|
235 |
disabled. (i.e. on-hold). |
|
236 |
Interrupts will be delivered when |
|
237 |
reenabled. |
|
238 |
||
239 |
exceptionHandlerSet <ExceptionhandlerSet> |
|
240 |
Handled by any process; allows for |
|
241 |
exceptionHandlers and query-answerers to |
|
242 |
be added/removed dynamically. |
|
4646
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
243 |
|
1273 | 244 |
[Class variables:] |
159 | 245 |
|
19969 | 246 |
TerminateSignal <Signal> signal used to terminate processes |
247 |
(should not be caught - or at least |
|
248 |
rejected in handlers). |
|
249 |
If caught and proceeded, a process |
|
250 |
cannot be terminated via #terminate. |
|
251 |
For hardTermination (in case of emergency), |
|
252 |
send it a #erminateNoSignal message. |
|
253 |
||
254 |
RestartSignal <Signal> signal used to restart a process. |
|
255 |
Can be caught in additional handler(s), |
|
256 |
to perform all kind of re-initialization. |
|
257 |
However, these handlers should reject, |
|
258 |
for the restart to be really performed. |
|
1273 | 259 |
|
260 |
[see also:] |
|
19969 | 261 |
ProcessorScheduler |
262 |
Block |
|
263 |
Sempahore SemaphoreSet Delay SharedQueue |
|
264 |
WindowGroup |
|
265 |
(``Working with processes'': programming/processes.html) |
|
1273 | 266 |
|
1294 | 267 |
[author:] |
19969 | 268 |
Claus Gittinger |
1294 | 269 |
|
88 | 270 |
" |
213 | 271 |
! |
272 |
||
14722 | 273 |
examples |
213 | 274 |
" |
275 |
start a background process, computing 1000 factorial 100 times; |
|
276 |
the processes priority is set to not disturb any interactive process. |
|
277 |
Since its prio is higher than the 3D animation demos prio, you will notice, |
|
278 |
that those are suspended while the computation runs. But Interactive views |
|
279 |
(like browsers) will continue to react normal. |
|
5450 | 280 |
[exBegin] |
213 | 281 |
[ |
282 |
'starting' printNL. |
|
283 |
100 timesRepeat:[1000 factorial]. |
|
284 |
'done with factorial' printNL. |
|
285 |
] forkAt:(Processor userBackgroundPriority). |
|
5450 | 286 |
[exEnd] |
213 | 287 |
|
288 |
||
289 |
start a background process, computing 1000 factorial 100 times; |
|
290 |
the processes priority is set to not disturb any process. |
|
291 |
The prio is set to 1 (which is the lowest possible) notice that now, |
|
14722 | 292 |
the 3D animation demos also continue to run. |
5450 | 293 |
[exBegin] |
213 | 294 |
[ |
295 |
'starting' printNL. |
|
296 |
100 timesRepeat:[1000 factorial]. |
|
297 |
'done with factorial' printNL. |
|
298 |
] forkAt:1. |
|
5450 | 299 |
[exEnd] |
213 | 300 |
|
301 |
||
302 |
start a background process, reading a pipe without blocking other |
|
303 |
processes; |
|
5450 | 304 |
[exBegin] |
213 | 305 |
[ |
306 |
|p| |
|
307 |
||
308 |
'starting' printNL. |
|
309 |
p := PipeStream readingFrom:'ls -lR .'. |
|
310 |
[p atEnd] whileFalse:[ |
|
5450 | 311 |
p readWait. |
312 |
p nextLine printNL. |
|
213 | 313 |
]. |
314 |
p close. |
|
315 |
'done with pipe' printNL. |
|
316 |
] forkAt:1. |
|
5450 | 317 |
[exEnd] |
213 | 318 |
|
14722 | 319 |
see more examples in doc/coding |
213 | 320 |
(or search in the browser for senders of fork*) |
321 |
" |
|
88 | 322 |
! ! |
1 | 323 |
|
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
324 |
!Process class methodsFor:'initialization'! |
159 | 325 |
|
326 |
initialize |
|
327 |
TerminateSignal isNil ifTrue:[ |
|
14722 | 328 |
TerminateSignal := TerminateProcessRequest. |
329 |
TerminateSignal notifierString:'unhandled process termination'. |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
330 |
|
14722 | 331 |
RestartSignal := RestartProcessRequest. |
332 |
RestartSignal notifierString:'unhandled process restart'. |
|
302 | 333 |
|
16562 | 334 |
CaughtSignals := SignalSet |
14722 | 335 |
with:AbortAllOperationRequest |
336 |
with:TerminateProcessRequest |
|
337 |
with:RestartProcessRequest. |
|
159 | 338 |
] |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
339 |
|
6212 | 340 |
"Modified: / 17.11.2001 / 11:07:29 / cg" |
159 | 341 |
! ! |
342 |
||
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
343 |
!Process class methodsFor:'instance creation'! |
699 | 344 |
|
345 |
for:aBlock priority:aPrio |
|
346 |
"create a new (unscheduled) process which will execute aBlock at |
|
347 |
a given priority, once scheduled. The process will start execution once |
|
348 |
it gets a #resume-message." |
|
349 |
||
2268
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
350 |
^ self basicNew for:aBlock priority:aPrio |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
351 |
|
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
352 |
"Modified: 25.1.1997 / 01:23:12 / cg" |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
353 |
! |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
354 |
|
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
355 |
new |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
356 |
"create a new (unscheduled) process which will execute the start |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
357 |
method, when scheduled. The process will start execution once |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
358 |
it gets a #resume-message." |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
359 |
|
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
360 |
^ self basicNew for:nil priority:(Processor activePriority). |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
361 |
|
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
362 |
"Created: 25.1.1997 / 01:31:05 / cg" |
699 | 363 |
! ! |
364 |
||
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
365 |
!Process class methodsFor:'Signal constants'! |
159 | 366 |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
367 |
restartSignal |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
368 |
"return the signal used for process restart" |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
369 |
|
22693 | 370 |
^ RestartProcessRequest |
371 |
||
372 |
"Created: / 28-10-1996 / 20:26:50 / cg" |
|
373 |
"Modified: / 23-04-2018 / 14:01:47 / stefan" |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
374 |
! |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
375 |
|
159 | 376 |
terminateSignal |
202 | 377 |
"return the signal used for process termination" |
378 |
||
22693 | 379 |
^ TerminateProcessRequest |
380 |
||
381 |
"Modified: / 23-04-2018 / 14:00:26 / stefan" |
|
159 | 382 |
! ! |
383 |
||
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
384 |
!Process class methodsFor:'defaults'! |
1346
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
385 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
386 |
defaultMaximumStackSize |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
387 |
"return the default max stack size. All new processes get |
14722 | 388 |
this limit initially. |
389 |
It may be changed for individual processes with: |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
390 |
aProcess setMaximumStackSize:limit" |
1346
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
391 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
392 |
%{ /* NOCONTEXT */ |
19293 | 393 |
extern INT __defaultThreadMaxStackSize(); |
1346
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
394 |
|
8913 | 395 |
RETURN ( __mkSmallInteger( __defaultThreadMaxStackSize() )); |
1346
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
396 |
%} |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
397 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
398 |
" |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
399 |
Process defaultMaximumStackSize |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
400 |
" |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
401 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
402 |
"Modified: 8.5.1996 / 10:22:24 / cg" |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
403 |
! |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
404 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
405 |
defaultMaximumStackSize:numberOfBytes |
14722 | 406 |
"set the default max stack size, return the previous value. |
407 |
All new processes get this stack limit initially. |
|
408 |
It may be changed for individual processes with: |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
409 |
aProcess setMaximumStackSize:limit |
1346
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
410 |
Notice: |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
411 |
There is seldom any need to change the default setting, |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
412 |
except for highly recursive programs." |
1346
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
413 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
414 |
%{ /* NOCONTEXT */ |
19293 | 415 |
extern INT __threadSetDefaultMaxStackSize(); |
1346
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
416 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
417 |
if (__isSmallInteger(numberOfBytes)) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
418 |
RETURN ( __mkSmallInteger(__threadSetDefaultMaxStackSize(__intVal(numberOfBytes)) )); |
1352 | 419 |
} |
1346
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
420 |
%} |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
421 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
422 |
" |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
423 |
Process defaultMaximumStackSize:500*1024 |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
424 |
" |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
425 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
426 |
"Modified: 8.5.1996 / 10:23:26 / cg" |
19292 | 427 |
! |
428 |
||
429 |
wrapStackSize |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
430 |
"return the wrap stack size. |
19292 | 431 |
Under windows, blocking API calls are executed on a separate stack with this size. |
432 |
If you ever encounter that a call to n external library function requires more stack than |
|
433 |
this, you may change this size in your startup (or programmatically) during early startup. |
|
434 |
Returns nil on non-windows machines." |
|
435 |
||
436 |
%{ /* NOCONTEXT */ |
|
437 |
INT sz = 0; |
|
438 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
439 |
#ifdef __win32__ |
19292 | 440 |
extern INT __getWrapStackSize(); |
441 |
||
442 |
sz = __getWrapStackSize(); |
|
443 |
#endif |
|
19295 | 444 |
RETURN (__MKINT(sz)); |
19292 | 445 |
%} |
446 |
! |
|
447 |
||
448 |
wrapStackSize:newSize |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
449 |
"set the wrap stack size. |
19292 | 450 |
Under windows, blocking API calls are executed on a separate stack with this size. |
451 |
If you ever encounter that a call to n external library function requires more stack than |
|
452 |
this, you may change this size in your startup (or programmatically) during early startup. |
|
453 |
An argument of 0 changes the size back to the default. |
|
454 |
Returns the previous size." |
|
455 |
||
456 |
%{ /* NOCONTEXT */ |
|
457 |
INT __oldSize = 0; |
|
458 |
||
459 |
if (__isSmallInteger(newSize)) { |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
460 |
INT __newSize = __intVal(newSize); |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
461 |
|
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
462 |
if (__newSize >= 0) { |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
463 |
#ifdef __win32__ |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
464 |
extern INT __setWrapStackSize(INT); |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
465 |
|
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
466 |
__oldSize = __setWrapStackSize(__newSize); |
19292 | 467 |
#endif |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
468 |
} |
19292 | 469 |
} |
19295 | 470 |
RETURN (__MKINT(__oldSize)); |
19292 | 471 |
%} |
1346
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
472 |
! ! |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
473 |
|
3783
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
474 |
!Process class methodsFor:'instance retrieval'! |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
475 |
|
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
476 |
findProcessWithId:id |
21129 | 477 |
<resource: #obsolete> |
3783
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
478 |
"return a process with a particular id. |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
479 |
This is only a debugging helper, to allow |
21129 | 480 |
easy access of a process by name in the MiniDebugger. |
481 |
Do not use - ask Processor instead!!" |
|
482 |
||
3783
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
483 |
|
9226 | 484 |
^ self allSubInstances detect:[:aProcess | aProcess id = id] ifNone:nil. |
3783
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
485 |
|
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
486 |
" |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
487 |
Process findProcessWithId:1 |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
488 |
" |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
489 |
|
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
490 |
"Modified: / 26.8.1998 / 15:39:55 / cg" |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
491 |
! |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
492 |
|
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
493 |
findProcessWithName:name |
21129 | 494 |
<resource: #obsolete> |
3783
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
495 |
"return a process with a particular name. |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
496 |
This is only a debugging helper, to allow |
21129 | 497 |
easy access of a process by name in the MiniDebugger |
498 |
Do not use - ask Processor instead!!" |
|
3783
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
499 |
|
9226 | 500 |
^ self allSubInstances detect:[:aProcess | aProcess name = name] ifNone:nil. |
3783
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
501 |
|
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
502 |
" |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
503 |
Process findProcessWithName:'scheduler' |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
504 |
" |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
505 |
|
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
506 |
"Modified: / 26.8.1998 / 15:40:54 / cg" |
9008
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
507 |
! |
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
508 |
|
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
509 |
findProcessesWithGroupId:aGroupId |
21129 | 510 |
<resource: #obsolete> |
9008
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
511 |
"return a collection of processes with the particular group id. |
21129 | 512 |
Do not use - ask Processor instead!!" |
9008
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
513 |
|
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
514 |
^ self allSubInstances select:[:aProcess | aProcess processGroupId = aGroupId ]. |
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
515 |
|
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
516 |
" |
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
517 |
Process findProcessesWithGroupId: 0 |
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
518 |
" |
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
519 |
|
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
520 |
"Modified: / 26.8.1998 / 15:40:54 / cg" |
3783
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
521 |
! ! |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
522 |
|
16182 | 523 |
|
21333 | 524 |
|
24238 | 525 |
|
699 | 526 |
!Process methodsFor:'accessing'! |
527 |
||
4874
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
528 |
beGUIProcess |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
529 |
"mark the receiver as a gui process. |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
530 |
This is currently not used, but allows end-user applications |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
531 |
to terminate all subprocesses which are GUI related, and leave |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
532 |
other background processes in the same process group untouched." |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
533 |
|
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
534 |
processType := #gui |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
535 |
! |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
536 |
|
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
537 |
beGroupLeader |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
538 |
"make the receiver a processGroupLeader. |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
539 |
This detaches the process from its creator, so that it will not |
10742 | 540 |
be terminated when it terminates via #terminateGroup. |
5088 | 541 |
Also, processes forked from a groupLeader belong to that group |
542 |
and can be terminated via #terminateGroup - unless they become |
|
543 |
group leaders themself. |
|
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
544 |
(windowgroup processes do this)." |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
545 |
|
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
546 |
processGroupId := id |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
547 |
|
10742 | 548 |
"Created: / 08-07-1996 / 14:08:44 / cg" |
549 |
"Modified: / 17-10-2007 / 10:49:09 / cg" |
|
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
550 |
! |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
551 |
|
2196 | 552 |
beSystemProcess |
553 |
"make the receiver a system process. |
|
554 |
These processes have a groupId of 0. |
|
555 |
When executed as standAlone application, smalltalk exits when |
|
556 |
no more user processes are running. |
|
5088 | 557 |
(i.e. when there are only systemProcesses left) |
2196 | 558 |
To prevent any daemon processes from preventing this exit, |
5088 | 559 |
you should make them systemProcesses" |
2196 | 560 |
|
561 |
processGroupId := 0 |
|
562 |
||
563 |
"Created: 17.1.1997 / 21:42:46 / cg" |
|
564 |
! |
|
565 |
||
699 | 566 |
changePriority:aNumber |
567 |
"same as priority:, but returns the old priority. |
|
818 | 568 |
(cannot do this in #priority: for ST-80 compatibility)" |
699 | 569 |
|
570 |
|oldPrio| |
|
571 |
||
572 |
oldPrio := prio. |
|
573 |
Processor changePriority:aNumber for:self. |
|
574 |
^ oldPrio |
|
818 | 575 |
|
576 |
"Modified: 23.12.1995 / 18:38:53 / cg" |
|
699 | 577 |
! |
578 |
||
1530
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
579 |
creatorId |
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
580 |
"return the processcreators id. |
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
581 |
This has no semantic meaning, but is useful to identify processes |
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
582 |
when debugging." |
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
583 |
|
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
584 |
^ creatorId |
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
585 |
! |
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
586 |
|
4646
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
587 |
exceptionHandlerSet |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
588 |
"retrieve the exceptionHandlerSet, which includes the set of |
23258 | 589 |
exceptions which are caught by the process. |
4646
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
590 |
Initially being empty, this allows for default handlers to be |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
591 |
dynamically added/removed from the set of handled exceptions/queries." |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
592 |
|
4877 | 593 |
exceptionHandlerSet isNil ifTrue:[ |
23258 | 594 |
exceptionHandlerSet := ExceptionHandlerSet new. |
4877 | 595 |
]. |
4646
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
596 |
^ exceptionHandlerSet |
23258 | 597 |
|
598 |
"Modified (comment): / 03-08-2018 / 08:48:38 / Claus Gittinger" |
|
4646
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
599 |
! |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
600 |
|
818 | 601 |
id |
602 |
"return the processes id" |
|
603 |
||
604 |
^ id |
|
605 |
! |
|
606 |
||
607 |
name |
|
608 |
"return the processes name" |
|
609 |
||
610 |
^ name |
|
611 |
! |
|
612 |
||
613 |
name:aString |
|
614 |
"set the processes name" |
|
615 |
||
616 |
name := aString |
|
617 |
! |
|
618 |
||
619 |
priority |
|
19452 | 620 |
"return the receiver's priority" |
818 | 621 |
|
622 |
^ prio |
|
623 |
! |
|
624 |
||
625 |
priority:aNumber |
|
626 |
"set my priority" |
|
627 |
||
628 |
Processor changePriority:aNumber for:self. |
|
629 |
! |
|
630 |
||
3679 | 631 |
priorityRange |
3723 | 632 |
"return my dynamic priority range" |
3679 | 633 |
|
634 |
^ priorityRange |
|
635 |
||
3723 | 636 |
"Modified: / 3.8.1998 / 22:55:53 / cg" |
3679 | 637 |
! |
638 |
||
639 |
priorityRange:anInterval |
|
3723 | 640 |
"change my dynamic priority range" |
3679 | 641 |
|
16421 | 642 |
|lowPri hiPri newPrio| |
9084 | 643 |
|
644 |
priorityRange := anInterval. |
|
645 |
anInterval notNil ifTrue:[ |
|
16562 | 646 |
lowPri := priorityRange start. |
647 |
hiPri := priorityRange stop. |
|
648 |
(newPrio := prio) isNil ifTrue:[ |
|
649 |
newPrio := lowPri |
|
650 |
] ifFalse:[ |
|
651 |
prio < lowPri ifTrue:[ |
|
652 |
newPrio := lowPri |
|
653 |
] ifFalse:[ |
|
654 |
prio > hiPri ifTrue:[ |
|
655 |
newPrio := hiPri |
|
656 |
]. |
|
657 |
]. |
|
658 |
]. |
|
659 |
newPrio ~~ prio ifTrue:[ |
|
660 |
self priority:newPrio |
|
661 |
] |
|
9084 | 662 |
]. |
3679 | 663 |
|
3723 | 664 |
"Modified: / 3.8.1998 / 22:56:05 / cg" |
3679 | 665 |
! |
666 |
||
1529
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
667 |
processGroupId |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
668 |
"return the processes processGroup id. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
669 |
Normally, when created, a processes creator id is taken and used |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
670 |
as the processGroup id. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
671 |
When #terminateGroup is sent to a process, the process and all of its |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
672 |
group members are terminated together. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
673 |
|
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
674 |
Processes can detach themself from the process group to prevent being |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
675 |
killed when the parent terminates (windowgroup processes do this)." |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
676 |
|
1530
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
677 |
^ processGroupId |
1529
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
678 |
|
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
679 |
"Created: 8.7.1996 / 13:47:47 / cg" |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
680 |
! |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
681 |
|
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
682 |
processGroupId:aGroupLeadersProcessID |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
683 |
"set the processes processGroup id. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
684 |
Normally, when created, a processes creator id is taken and used |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
685 |
as the processGroup id. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
686 |
When #terminateGroup is sent to a process, the process and all of its |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
687 |
group members are terminated together. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
688 |
|
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
689 |
Processes can detach themself from the process group to prevent being |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
690 |
killed when the parent terminates (windowgroup processes do this)." |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
691 |
|
1530
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
692 |
processGroupId := aGroupLeadersProcessID |
1529
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
693 |
|
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
694 |
"Created: 8.7.1996 / 13:47:53 / cg" |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
695 |
! |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
696 |
|
818 | 697 |
restartable:aBoolean |
698 |
"set/clear, the restartable flag. |
|
699 |
Restartable processes will automatically be restarted by the |
|
14722 | 700 |
ProcessorScheduler upon image restart. |
818 | 701 |
Others have to be restarted manually." |
702 |
||
24058 | 703 |
startTimestamp notNil ifTrue:[ |
23016 | 704 |
self proceedableError:'cannot be made restartable when already started'. |
705 |
^ self |
|
818 | 706 |
]. |
707 |
restartable := aBoolean |
|
708 |
||
23016 | 709 |
"Modified: / 23-12-1995 / 18:38:32 / cg" |
710 |
"Modified: / 24-05-2018 / 21:04:04 / Claus Gittinger" |
|
24058 | 711 |
"Modified: / 11-04-2019 / 14:52:12 / Stefan Vogel" |
818 | 712 |
! |
713 |
||
24224 | 714 |
setStateRun |
715 |
"set the state - only to be used from scheduler" |
|
716 |
||
717 |
state := #run |
|
718 |
||
719 |
"Created: / 29-05-2019 / 01:04:38 / Claus Gittinger" |
|
720 |
! |
|
721 |
||
818 | 722 |
singleStep:aBoolean |
723 |
singleStepping := aBoolean |
|
724 |
! |
|
725 |
||
726 |
startBlock |
|
727 |
"return the processes startup-block" |
|
728 |
||
729 |
^ startBlock |
|
730 |
! |
|
731 |
||
21326 | 732 |
startTimestamp |
733 |
"return the processes' start time" |
|
734 |
||
735 |
startTimestamp notNil ifTrue:[ |
|
736 |
^ startTimestamp |
|
737 |
]. |
|
24058 | 738 |
id == 0 ifTrue:[ |
739 |
"/ the very first system process has no starttime set |
|
740 |
startTimestamp := Smalltalk imageStartTime. |
|
741 |
]. |
|
21326 | 742 |
^ startTimestamp |
24058 | 743 |
|
744 |
"Modified: / 11-04-2019 / 15:16:02 / Stefan Vogel" |
|
21326 | 745 |
! |
746 |
||
818 | 747 |
state |
748 |
"return a symbol describing the processes state" |
|
749 |
||
750 |
^ state |
|
751 |
! |
|
752 |
||
753 |
state:aSymbol |
|
754 |
"set the state - only to be used from scheduler" |
|
755 |
||
756 |
state := aSymbol |
|
757 |
! |
|
758 |
||
759 |
suspendedContext |
|
14722 | 760 |
"return the processes suspended context |
818 | 761 |
- this is the context from which a process switch into the scheduler |
20251 | 762 |
or another process occurred. |
5088 | 763 |
For the active process, a dead process, or one which |
2888
3e8b5166d90f
a rocess which had no chance yet to run, can be #terminated with
Claus Gittinger <cg@exept.de>
parents:
2857
diff
changeset
|
764 |
had no chance to run yet, nil is returned. |
818 | 765 |
Typically, only the debugger is interested in this one." |
766 |
||
767 |
%{ /* NOCONTEXT */ |
|
768 |
OBJ i; |
|
769 |
||
1133 | 770 |
if (__isSmallInteger(i = __INST(id))) { |
20251 | 771 |
RETURN (__threadContext(__intVal(i))); |
818 | 772 |
} |
773 |
%}. |
|
774 |
^ nil |
|
775 |
! ! |
|
776 |
||
777 |
!Process methodsFor:'accessing-change notifications'! |
|
778 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
779 |
addExitAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
780 |
"add aBlock to the processes exit actions. |
5088 | 781 |
This block will be evaluated right before the process dies, |
782 |
and can be used to trigger actions somewhere else (i.e. synchronization)." |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
783 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
784 |
exitActions isNil ifTrue:[ |
5450 | 785 |
exitActions := OrderedCollection new |
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
786 |
]. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
787 |
exitActions add:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
788 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
789 |
"Created: 12.1.1997 / 00:34:51 / cg" |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
790 |
! |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
791 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
792 |
addSuspendAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
793 |
"add aBlock to the processes suspend actions. |
5088 | 794 |
This block will be evaluated when a process gets suspended. |
14722 | 795 |
You may ask what that is useful for - it is useful to flush |
5088 | 796 |
buffered graphic commands of a GUI process (i.e. to force xlib |
797 |
to send buffered commands to the display)." |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
798 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
799 |
suspendActions isNil ifTrue:[ |
5450 | 800 |
suspendActions := OrderedCollection new |
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
801 |
]. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
802 |
suspendActions add:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
803 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
804 |
"Modified: 13.12.1995 / 13:44:31 / stefan" |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
805 |
"Created: 12.1.1997 / 00:35:11 / cg" |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
806 |
! |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
807 |
|
699 | 808 |
emergencySignalHandler |
809 |
"return the emergencySignalHandler block. |
|
810 |
See Signal>>documentation for more info." |
|
811 |
||
812 |
^ emergencySignalHandler |
|
813 |
! |
|
814 |
||
815 |
emergencySignalHandler:aOneArgBlock |
|
816 |
"set the emergencySignalHandler block. |
|
817 |
See Signal>>documentation for more info." |
|
818 |
||
819 |
emergencySignalHandler := aOneArgBlock |
|
820 |
! |
|
821 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
822 |
removeAllExitActions |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
823 |
"remove all exit actions." |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
824 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
825 |
exitActions := nil. |
699 | 826 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
827 |
"Created: 12.1.1997 / 00:36:02 / cg" |
699 | 828 |
! |
829 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
830 |
removeAllSuspendActions |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
831 |
"remove all suspend actions." |
699 | 832 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
833 |
suspendActions := nil. |
699 | 834 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
835 |
"Created: 12.1.1997 / 00:36:16 / cg" |
13016 | 836 |
! |
837 |
||
838 |
removeExitAction:anExitAction ifAbsent:exceptionBlock |
|
839 |
"remove the identical exitAction; if found, remove and return it; |
|
840 |
if not, return the value from evaluating exceptionBlock" |
|
841 |
||
842 |
exitActions notNil ifTrue:[ |
|
14722 | 843 |
^ exitActions removeIdentical:anExitAction ifAbsent:exceptionBlock. |
13016 | 844 |
]. |
845 |
^ exceptionBlock value. |
|
24238 | 846 |
! |
847 |
||
848 |
terminateActionBlock:aBlock |
|
849 |
"for compatibility with OSProcess, |
|
850 |
this adds a block to be called when the process terminates" |
|
851 |
||
852 |
self addExitAction:aBlock |
|
853 |
||
854 |
"Created: / 29-05-2019 / 23:18:12 / Claus Gittinger" |
|
818 | 855 |
! ! |
699 | 856 |
|
818 | 857 |
!Process methodsFor:'accessing-stack'! |
699 | 858 |
|
859 |
maximumStackSize |
|
14722 | 860 |
"returns the processes stack limit - i.e. the process will be |
699 | 861 |
interrupted with a recursionSignal-raise, if it ever |
862 |
needs more stack (in bytes) than this number" |
|
863 |
||
864 |
%{ /* NOCONTEXT */ |
|
19294 | 865 |
extern INT __threadMaxStackSize(); |
699 | 866 |
OBJ i; |
867 |
||
1133 | 868 |
if (__isSmallInteger(i = __INST(id))) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
869 |
RETURN( __MKINT(__threadMaxStackSize(__intVal(i))) ); |
699 | 870 |
} |
871 |
%}. |
|
872 |
^ nil |
|
873 |
! |
|
874 |
||
875 |
setMaximumStackSize:limit |
|
876 |
"sets the processes stack limit - i.e. the process will be |
|
877 |
interrupted with a recursionSignal-raise, if it ever |
|
878 |
needs more stack (in bytes) than this number. |
|
879 |
Returns the old value." |
|
880 |
||
881 |
%{ /* NOCONTEXT */ |
|
19294 | 882 |
extern INT __threadSetMaxStackSize(int, unsigned INT); |
699 | 883 |
OBJ i; |
884 |
||
14722 | 885 |
if (__isSmallInteger(i = __INST(id)) |
699 | 886 |
&& __isSmallInteger(limit) ) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
887 |
RETURN ( __MKINT(__threadSetMaxStackSize(__intVal(i), __intVal(limit))) ); |
699 | 888 |
} |
889 |
%}. |
|
890 |
^ nil |
|
891 |
! |
|
892 |
||
712
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
893 |
setStackInitialSize:initial increment:increment safe:safe |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
894 |
"hook for fine-tuning. Sets the processes initialStackSize- and |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
895 |
and stackIncrement-parameters. Not for normal use." |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
896 |
|
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
897 |
%{ /* NOCONTEXT */ |
19294 | 898 |
extern INT __threadSetJunkSizes(int, unsigned INT, unsigned INT, unsigned INT); |
19296 | 899 |
|
712
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
900 |
OBJ i; |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
901 |
|
1133 | 902 |
if (__isSmallInteger(i = __INST(id)) |
712
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
903 |
&& __isSmallInteger(initial) |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
904 |
&& __isSmallInteger(increment) |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
905 |
&& __isSmallInteger(safe)) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
906 |
RETURN ( __threadSetJunkSizes(__intVal(i), __intVal(initial), __intVal(increment), __intVal(safe)) ? true : false ); |
712
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
907 |
} |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
908 |
%}. |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
909 |
^ false |
699 | 910 |
! ! |
911 |
||
24058 | 912 |
|
699 | 913 |
!Process methodsFor:'interrupts'! |
914 |
||
2725
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
915 |
blockInterrupts |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
916 |
"disable interrupt processing for the receiver process |
14722 | 917 |
- if disabled, incoming interrupts will be registered and handled as |
2725
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
918 |
soon as interrupts are reenabled via unblockInterrupts. |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
919 |
Returns the previous blocking status i.e. true if interrupts |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
920 |
where already blocked. You need this information for proper |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
921 |
unblocking, in case of nested block/unblock calls. |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
922 |
This is similar to OperatingSystem>>blockInterrupts, but only |
14722 | 923 |
affects interrupts for the receiver process |
2725
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
924 |
(i.e. those which are installed via #interruptWith:)" |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
925 |
|
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
926 |
|disabledBefore| |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
927 |
|
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
928 |
disabledBefore := interruptsDisabled. |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
929 |
interruptsDisabled := true. |
22326 | 930 |
^ disabledBefore |
2726 | 931 |
|
932 |
" |
|
933 |
|p1| |
|
934 |
||
935 |
p1 := [ |
|
22326 | 936 |
Transcript showCR:'disabled ...'. |
937 |
Transcript showCR:Processor activeProcess blockInterrupts. |
|
938 |
Transcript showCR:'busy ...'. |
|
939 |
Delay waitForSeconds:10. |
|
940 |
Transcript showCR:'enabled ...'. |
|
941 |
Processor activeProcess unblockInterrupts. |
|
942 |
] forkAt:9. |
|
2726 | 943 |
|
944 |
p1 interruptWith:[Transcript showCR:'interrupted']. |
|
945 |
" |
|
22326 | 946 |
|
947 |
"Modified: / 25-10-2017 / 18:03:39 / stefan" |
|
2725
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
948 |
! |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
949 |
|
5491 | 950 |
hasInterruptActions |
951 |
"return true, if there are any interrupt actions to evaluate |
|
952 |
(i.e. if the receiver has been interrupted)." |
|
953 |
||
8544
732ed0a3d7ca
use #~~ instead of #> for speed
Stefan Vogel <sv@exept.de>
parents:
8495
diff
changeset
|
954 |
^ interruptActions size ~~ 0 |
5491 | 955 |
! |
956 |
||
699 | 957 |
interruptWith:aBlock |
958 |
"interrupt the receiver and make it evaluate aBlock. |
|
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
959 |
If the receiver is currently suspended it is resumed. |
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
960 |
Notice, that the process will only perform the block immediately, |
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
961 |
IFF its priority is higher than the current processes priority. |
22628 | 962 |
Otherwise, it will remain suspended, until its time comes. |
963 |
||
964 |
aBlock is evaluated with an optional argument: the context, that has been |
|
965 |
interrupted." |
|
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
966 |
|
21448 | 967 |
Processor activeProcess == self ifTrue:[ |
21447 | 968 |
aBlock value |
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
969 |
] ifFalse:[ |
21448 | 970 |
self isDead ifTrue:[ |
21463 | 971 |
"/ trying to register interrupt for dead process. |
972 |
^ self. |
|
21448 | 973 |
]. |
21447 | 974 |
self addInterruptAction:aBlock. |
975 |
Processor scheduleForInterrupt:self. |
|
2724 | 976 |
]. |
8613
b74b646a830b
no, last change leads to a blocking Debugger
Claus Gittinger <cg@exept.de>
parents:
8591
diff
changeset
|
977 |
|
21447 | 978 |
" |
979 |
Processor timeoutHandlerProcess interruptWith:[Transcript showCR:Processor activeProcess]. |
|
980 |
||
981 |
|p| |
|
982 |
p := [] fork. |
|
983 |
p waitUntilTerminated. |
|
984 |
p interruptWith:[Transcript showCR:Processor activeProcess]. |
|
985 |
" |
|
986 |
||
987 |
"Modified: / 12-01-1997 / 00:52:05 / cg" |
|
21463 | 988 |
"Modified: / 16-02-2017 / 18:09:38 / stefan" |
22628 | 989 |
"Modified (comment): / 16-03-2018 / 15:34:46 / stefan" |
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
990 |
! |
699 | 991 |
|
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
992 |
onResumeDo:aBlock |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
993 |
"prepare for the receiver to evaluate aBlock when resumed. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
994 |
This is like #interruptWith:, but does not resume the receiver |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
995 |
(i.e. it continues its sleep). |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
996 |
This is useful to place a breakpoint on a sleeping process, to be fired |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
997 |
when it awakes." |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
998 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
999 |
self addInterruptAction:aBlock. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1000 |
Processor scheduleInterruptActionsOf:self. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1001 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1002 |
"Created: 5.3.1996 / 17:28:04 / cg" |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1003 |
"Modified: 8.3.1996 / 13:01:21 / cg" |
2839
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1004 |
! |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1005 |
|
2857
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1006 |
stepInterruptHandler:anObject |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1007 |
"set the handler for stepInterrupts occurring in the receiver process. |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1008 |
This is an interface for the debugger and allows it to monitor a threads |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1009 |
stepInterrupts. Returns the previous handler. |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1010 |
Not for general use." |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1011 |
|
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1012 |
%{ /* NOCONTEXT */ |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1013 |
extern OBJ __threadStepInterruptHandler(); |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1014 |
|
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1015 |
RETURN( __threadStepInterruptHandler(anObject) ); |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1016 |
%} |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1017 |
! |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1018 |
|
2839
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1019 |
unblockInterrupts |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1020 |
"enable interrupt processing for the receiver process |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1021 |
- if any interrupts are pending, these will be handled immediately. |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1022 |
When unblocking interrupts, take care of nested block/unblock |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1023 |
calls - you should only unblock after a blockcall if they where |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1024 |
really not blocked before. |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1025 |
This is similar to OperatingSystem>>unblockInterrupts, but only |
14722 | 1026 |
affects interrupts for the receiver process |
2839
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1027 |
(i.e. those which are installed via #interruptWith:)" |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1028 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1029 |
interruptsDisabled := false. |
21008 | 1030 |
(interruptActions size ~~ 0 and:[Processor activeProcess == self]) ifTrue:[ |
1031 |
self interrupt. |
|
2839
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1032 |
] |
699 | 1033 |
! ! |
1034 |
||
21447 | 1035 |
!Process methodsFor:'interrupts-private'! |
1036 |
||
1037 |
addInterruptAction:aBlock |
|
1038 |
"make the receiver evaluate aBlock when resumed/interrupted. |
|
1039 |
The name is somewhat misleading (actually, its historic): |
|
1040 |
the block is also evaluated on resume." |
|
1041 |
||
1042 |
|wasBlocked| |
|
1043 |
||
1044 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1045 |
interruptActions isNil ifTrue:[ |
|
1046 |
interruptActions := OrderedCollection with:aBlock. |
|
1047 |
] ifFalse:[ |
|
1048 |
interruptActions addFirst:aBlock. |
|
1049 |
]. |
|
1050 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1051 |
! |
|
1052 |
||
1053 |
evaluateInterruptActionsWithContext:aContext |
|
1054 |
"evaluate my interrupt-actions." |
|
1055 |
||
22326 | 1056 |
|wasBlocked| |
1057 |
||
1058 |
wasBlocked := OperatingSystem blockInterrupts. |
|
21668 | 1059 |
[interruptActions notEmptyOrNil] whileTrue:[ |
22326 | 1060 |
|action| |
1061 |
||
21668 | 1062 |
action := interruptActions removeFirst. |
1063 |
interruptActions isEmpty ifTrue:[ |
|
1064 |
interruptActions := nil |
|
1065 |
]. |
|
1066 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
22326 | 1067 |
action valueWithOptionalArgument:aContext. |
1068 |
OperatingSystem blockInterrupts. |
|
21447 | 1069 |
]. |
22326 | 1070 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1071 |
||
1072 |
"Modified: / 25-10-2017 / 17:45:46 / stefan" |
|
21447 | 1073 |
! |
1074 |
||
1075 |
forceInterruptOnReturnOf:aContext |
|
1076 |
"helper entry for debugger. Force a stepInterrupt whenever aContext |
|
1077 |
returns either directly or via an unwind." |
|
1078 |
||
1079 |
aContext markForInterruptOnUnwind. |
|
1080 |
%{ |
|
1081 |
OBJ i; |
|
1082 |
||
1083 |
if (__isSmallInteger(i = __INST(id))) { |
|
1084 |
__threadContextStepInterrupt(__intVal(i), 1); |
|
1085 |
} |
|
1086 |
%} |
|
1087 |
||
1088 |
! |
|
1089 |
||
1090 |
interrupt |
|
1091 |
"evaluate my interrupt-actions. |
|
1092 |
The process will go back to where it got interrupted |
|
1093 |
after doing this. |
|
1094 |
||
1095 |
This is also sent by the VM." |
|
1096 |
||
1097 |
interruptActions size ~~ 0 ifTrue:[ |
|
1098 |
self evaluateInterruptActionsWithContext:thisContext sender. |
|
1099 |
]. |
|
1100 |
! |
|
1101 |
||
1102 |
interruptedIn:aContext |
|
1103 |
"evaluate my interrupt-actions. |
|
1104 |
This is indirectly called by the VM, when some #interruptWith: action |
|
1105 |
was scheduled for the process, and the process is resumed. |
|
1106 |
The process will go back to where it got interrupted after doing this." |
|
1107 |
||
1108 |
"/ the returned value here has a subtle effect: |
|
1109 |
"/ if false, the interrupt is assumed to be not taken, |
|
1110 |
"/ and will be redelivered. |
|
1111 |
||
22326 | 1112 |
interruptsDisabled ifTrue:[ |
21447 | 1113 |
"/ no, I don't want interrupts right now; |
1114 |
"/ try again later. |
|
1115 |
^ false |
|
1116 |
]. |
|
1117 |
||
1118 |
"/ I tend to disable interrupts, while processing interrupt actions; |
|
1119 |
"/ however, this leads to a blocking Debugger sometimes (scroll). |
|
1120 |
"/ [ |
|
1121 |
"/ interruptsDisabled := true. |
|
1122 |
self evaluateInterruptActionsWithContext:aContext. |
|
1123 |
"/ ] ensure:[ |
|
1124 |
"/ interruptsDisabled := false. |
|
1125 |
"/ ]. |
|
1126 |
^ true |
|
1127 |
||
22326 | 1128 |
"Created: / 18-10-1996 / 20:43:39 / cg" |
1129 |
"Modified: / 25-10-2017 / 18:04:01 / stefan" |
|
21447 | 1130 |
! ! |
1131 |
||
699 | 1132 |
!Process methodsFor:'monitoring'! |
1133 |
||
1134 |
numberOfStackBoundaryHits |
|
1135 |
"internal monitoring only - will vanish" |
|
1136 |
||
1137 |
%{ /* NOCONTEXT */ |
|
19294 | 1138 |
extern INT __threadNumberOfStackBoundaryHits(); |
1139 |
INT n; |
|
699 | 1140 |
OBJ i; |
159 | 1141 |
|
1133 | 1142 |
if (__isSmallInteger(i = __INST(id))) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
1143 |
n = __threadNumberOfStackBoundaryHits(__intVal(i)); |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
1144 |
n &= _MAX_INT; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
1145 |
RETURN( __mkSmallInteger(n) ); |
699 | 1146 |
} |
1147 |
%}. |
|
1148 |
^ nil |
|
1149 |
! |
|
1150 |
||
1151 |
numberOfStackSegments |
|
1152 |
"return the processes number of stack segments currently used. |
|
1153 |
This method is for monitoring purposes only - it may vanish." |
|
1154 |
||
1155 |
%{ /* NOCONTEXT */ |
|
19297 | 1156 |
extern int __threadStackSegments(); |
699 | 1157 |
OBJ i; |
1158 |
||
1133 | 1159 |
if (__isSmallInteger(i = __INST(id))) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
1160 |
RETURN( __mkSmallInteger((INT)__threadStackSegments(__intVal(i))) ); |
699 | 1161 |
} |
1162 |
%}. |
|
1163 |
^ nil |
|
1164 |
! |
|
1165 |
||
1166 |
totalStackSize |
|
1167 |
"return the processes maximum used stack size. |
|
1168 |
This method is for monitoring purposes only - it may vanish." |
|
1169 |
||
1170 |
%{ /* NOCONTEXT */ |
|
19294 | 1171 |
extern INT __threadTotalStackSize(); |
699 | 1172 |
OBJ i; |
1173 |
||
1133 | 1174 |
if (__isSmallInteger(i = __INST(id))) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
1175 |
RETURN( __MKINT(__threadTotalStackSize(__intVal(i))) ); |
699 | 1176 |
} |
1177 |
%}. |
|
1178 |
^ nil |
|
1179 |
! |
|
1180 |
||
1181 |
usedStackSize |
|
1182 |
"Return the processes current stack size. |
|
1183 |
This method is for monitoring purposes only - it may vanish." |
|
1184 |
||
1185 |
%{ /* NOCONTEXT */ |
|
14724 | 1186 |
extern unsigned INT __threadUsedStackSize(); |
699 | 1187 |
OBJ i; |
1188 |
||
1133 | 1189 |
if (__isSmallInteger(i = __INST(id))) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
1190 |
RETURN( __MKINT(__threadUsedStackSize(__intVal(i))) ); |
699 | 1191 |
} |
1192 |
%}. |
|
1193 |
^ nil |
|
1194 |
! |
|
1195 |
||
1196 |
vmTrace:aBoolean |
|
1197 |
"turn on/off VM message tracing for the receiver. |
|
1198 |
This is meant for ST/X debugging, and may vanish. |
|
1199 |
Expect lots of output, once this is turned on." |
|
1200 |
||
1201 |
%{ /* NOCONTEXT */ |
|
1202 |
OBJ i; |
|
1203 |
||
1133 | 1204 |
if (__isSmallInteger(i = __INST(id))) { |
1205 |
__threadTracing(__intVal(i), aBoolean); |
|
699 | 1206 |
} |
1207 |
%}. |
|
1208 |
! ! |
|
1209 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1210 |
!Process methodsFor:'obsolete'! |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1211 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1212 |
exitAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1213 |
"Obsoleted by addExitAction: / removeAllExitActions. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1214 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1215 |
Add aBlock to the processes exit actions. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1216 |
This block will be evaluated right before the process dies. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1217 |
An argument of nil removes all exitActions." |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1218 |
|
5870 | 1219 |
<resource:#obsolete> |
1220 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1221 |
self obsoleteMethodWarning:'use addExitAction: / removeAllExitActions'. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1222 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1223 |
aBlock isNil ifTrue:[ |
14722 | 1224 |
^ self removeAllExitActions. |
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1225 |
]. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1226 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1227 |
^ self addExitAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1228 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1229 |
"Modified: 13.12.1995 / 13:44:03 / stefan" |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1230 |
"Modified: 12.1.1997 / 00:39:59 / cg" |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1231 |
! |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1232 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1233 |
suspendAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1234 |
"Obsoleted by addSuspendAction: / removeAllSuspendActions. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1235 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1236 |
Add aBlock to the processes suspend actions. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1237 |
This block will be evaluated when a process gets suspended. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1238 |
A nil argument removes all suspendActions." |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1239 |
|
5870 | 1240 |
<resource:#obsolete> |
1241 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1242 |
self obsoleteMethodWarning:'use addSuspendAction: / removeAllSuspendActions'. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1243 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1244 |
aBlock isNil ifTrue:[ |
14722 | 1245 |
^ self removeAllSuspendActions. |
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1246 |
]. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1247 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1248 |
^ self addSuspendAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1249 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1250 |
"Modified: 12.1.1997 / 00:38:22 / cg" |
9361 | 1251 |
! |
1252 |
||
1253 |
terminateAllSubprocesses |
|
1254 |
<resource:#obsolete> |
|
1255 |
self obsoleteMethodWarning:'use #terminateAllSubprocessesInGroup'. |
|
1256 |
self terminateAllSubprocessesInGroup. |
|
1257 |
! |
|
1258 |
||
1259 |
terminateWithAllSubprocesses |
|
1260 |
<resource:#obsolete> |
|
1261 |
self obsoleteMethodWarning:'use #terminateWithAllSubprocessesInGroup'. |
|
1262 |
self terminateWithAllSubprocessesInGroup. |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1263 |
! ! |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1264 |
|
699 | 1265 |
!Process methodsFor:'printing & storing'! |
1266 |
||
1267 |
printOn:aStream |
|
1268 |
"a little more info in my printed representation" |
|
1269 |
||
1270 |
aStream nextPutAll:state article; |
|
14722 | 1271 |
space; |
1272 |
nextPutAll:state; |
|
1273 |
nextPutAll:' Process ('; |
|
1274 |
nextPutAll:self nameOrId. |
|
6944
491b35cf0bf3
printString changed to include id
Claus Gittinger <cg@exept.de>
parents:
6784
diff
changeset
|
1275 |
name notNil ifTrue:[ |
14722 | 1276 |
aStream |
1277 |
nextPutAll:', id='; |
|
1278 |
nextPutAll:id printString. |
|
6944
491b35cf0bf3
printString changed to include id
Claus Gittinger <cg@exept.de>
parents:
6784
diff
changeset
|
1279 |
]. |
14722 | 1280 |
aStream |
1281 |
nextPutAll:')' |
|
159 | 1282 |
! ! |
1283 |
||
1284 |
!Process methodsFor:'private'! |
|
1285 |
||
1286 |
for:aBlock priority:aPrio |
|
1287 |
"setup the new process - the receiver is not scheduled for |
|
1288 |
execution, to get it running, send it #resume" |
|
1289 |
||
339 | 1290 |
|nm active| |
159 | 1291 |
|
1292 |
prio := aPrio. |
|
1293 |
startBlock := aBlock. |
|
339 | 1294 |
restartable := false. |
22326 | 1295 |
interruptsDisabled := false. |
159 | 1296 |
|
10436
2782fa4bd45a
#newProcess et al never return nil - but raise an exception
Stefan Vogel <sv@exept.de>
parents:
9361
diff
changeset
|
1297 |
Processor newProcessFor:self. |
159 | 1298 |
|
1299 |
" |
|
1300 |
give me a user-friendly name |
|
1301 |
" |
|
339 | 1302 |
active := Processor activeProcess. |
2268
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
1303 |
(nm := active name) notNil ifTrue:[ |
22326 | 1304 |
" |
1305 |
avoid name inflation |
|
1306 |
" |
|
1307 |
(nm endsWith:' sub') ifFalse:[ |
|
1308 |
nm := nm , ' [' , active id printString , '] sub' |
|
1309 |
]. |
|
1310 |
name := nm |
|
1529
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
1311 |
]. |
5675
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1312 |
creatorId := active id. |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1313 |
processGroupId := active processGroupId. |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1314 |
(processGroupId isNil or:[processGroupId == 0]) ifTrue:[ |
22326 | 1315 |
processGroupId := creatorId. |
5675
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1316 |
]. |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1317 |
|
4880 | 1318 |
"/ since groupId is used to detect a systemProcess (0), |
1319 |
"/ do not allow a 0 here; need an explicit beSystemProcess. |
|
1320 |
processGroupId == 0 ifTrue:[processGroupId := nil]. |
|
1529
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
1321 |
|
22326 | 1322 |
"Modified: / 25-01-1997 / 01:28:54 / cg" |
1323 |
"Modified: / 25-10-2017 / 18:02:52 / stefan" |
|
5812
e23a3fdc75cb
already-dead is a proceedable error
Claus Gittinger <cg@exept.de>
parents:
5683
diff
changeset
|
1324 |
! ! |
159 | 1325 |
|
7257 | 1326 |
!Process methodsFor:'private-scheduler access'! |
1 | 1327 |
|
699 | 1328 |
setId:idNumber state:stateSymbol |
1329 |
"set id and state - not for public use" |
|
375 | 1330 |
|
699 | 1331 |
id := idNumber. |
4880 | 1332 |
creatorId := 0. |
1333 |
processGroupId := nil. |
|
699 | 1334 |
state := stateSymbol. |
8787 | 1335 |
singleStepping isNil ifTrue:[ |
14722 | 1336 |
singleStepping := false |
8787 | 1337 |
]. |
1338 |
restartable isNil ifTrue:[ |
|
14722 | 1339 |
restartable := false |
8787 | 1340 |
]. |
1341 |
interruptsDisabled isNil ifTrue:[ |
|
14722 | 1342 |
interruptsDisabled := false |
8787 | 1343 |
]. |
1844 | 1344 |
|
1345 |
"Modified: 30.10.1996 / 00:35:29 / cg" |
|
182 | 1346 |
! |
1347 |
||
159 | 1348 |
setPriority:aNumber |
1349 |
"set priority without telling processor - not for public use" |
|
1350 |
||
1351 |
prio := aNumber |
|
1352 |
! |
|
1353 |
||
1354 |
setStartBlock:aBlock |
|
19452 | 1355 |
"set the receiver's startup block" |
159 | 1356 |
|
1357 |
startBlock := aBlock |
|
1358 |
! |
|
13 | 1359 |
|
159 | 1360 |
setStateTo:newState if:oldState |
1361 |
state == oldState ifTrue:[state := newState] |
|
1362 |
! |
|
1363 |
||
1364 |
setStateTo:newState if:oldState1 or:oldState2 |
|
1365 |
(state == oldState1 or:[state == oldState2]) ifTrue:[state := newState] |
|
699 | 1366 |
! ! |
1367 |
||
818 | 1368 |
!Process methodsFor:'queries'! |
1369 |
||
5397 | 1370 |
isActive |
1371 |
"return true if I am the active process" |
|
1372 |
||
1373 |
^ Processor activeProcess == self |
|
1374 |
! |
|
1375 |
||
818 | 1376 |
isDead |
10553 | 1377 |
"return true, if the receiver is a dead process" |
818 | 1378 |
|
10553 | 1379 |
^ (id isNil or:[state isNil or:[state == #dead]]) |
818 | 1380 |
|
1381 |
"Modified: 23.12.1995 / 18:35:29 / cg" |
|
1382 |
! |
|
1383 |
||
14359 | 1384 |
isDebugged |
1385 |
"return true, iff the receiver process is currently being debugged |
|
1386 |
(i.e. is stopped and a debugger sits on top of it)" |
|
1387 |
||
1388 |
^ (state == #debug) |
|
1389 |
||
1390 |
"Created: / 26-09-2012 / 14:56:36 / cg" |
|
1391 |
! |
|
1392 |
||
24224 | 1393 |
isDebuggedOrStopped |
1394 |
"return true, iff the receiver process is currently being stopped |
|
1395 |
and possibly debugged (i.e. is stopped and a debugger sits on top of it)" |
|
1396 |
||
1397 |
^ (state == #debug) or:[state == #stopped] |
|
1398 |
||
1399 |
"Created: / 29-05-2019 / 01:01:20 / Claus Gittinger" |
|
1400 |
! |
|
1401 |
||
22526 | 1402 |
isDebuggerProcess |
1403 |
"return true, iff the receiver process is currently running a Debugger or |
|
1404 |
an Inspector. Senders may behave differently and e.g. timeout on |
|
1405 |
endless blocking operations." |
|
1406 |
||
1407 |
^ self environmentAt:#isDebuggerProcess ifAbsent:false. |
|
1408 |
||
1409 |
"Created: / 01-02-2018 / 10:15:49 / stefan" |
|
1410 |
! |
|
1411 |
||
4874
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1412 |
isGUIProcess |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1413 |
"return true, if this is a GUI process. |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1414 |
I.e. a windowGroup process. |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1415 |
This is currently not used, but allows end-user applications |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1416 |
to terminate all subprocesses which are GUI related, and leave |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1417 |
other background processes in the same process group untouched." |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1418 |
|
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1419 |
^ processType == #gui |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1420 |
! |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1421 |
|
818 | 1422 |
isRestartable |
1423 |
"return true, iff the receiver is restartable" |
|
1424 |
||
1425 |
^ restartable |
|
1426 |
! |
|
1427 |
||
24224 | 1428 |
isRunning |
1429 |
"return true, iff the receiver is running (state == #run); |
|
1430 |
this does not mean that it is currently active |
|
1431 |
(it might be suspended by the current process)" |
|
1432 |
||
1433 |
^ (state == #run) |
|
1434 |
||
1435 |
"Created: / 29-05-2019 / 01:00:17 / Claus Gittinger" |
|
1436 |
! |
|
1437 |
||
818 | 1438 |
isSingleStepping |
1439 |
^ singleStepping |
|
1440 |
! |
|
1441 |
||
5643 | 1442 |
isStopped |
1443 |
"return true, iff the receiver is stopped" |
|
1444 |
||
1445 |
^ (state == #stopped) |
|
1446 |
||
1447 |
"Modified: 23.12.1995 / 18:35:29 / cg" |
|
1448 |
! |
|
1449 |
||
2636
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1450 |
isSystemProcess |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1451 |
"return true if aProcess is a system process, |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1452 |
which should not be suspended/terminated etc.." |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1453 |
|
14722 | 1454 |
^ (Processor isPureEventDriven |
2636
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1455 |
or:[id == 0 |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1456 |
or:[processGroupId == 0 |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1457 |
or:[(Display notNil and:[Display dispatchProcess == self]) |
14722 | 1458 |
]]]) |
2636
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1459 |
|
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1460 |
" |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1461 |
Processor activeProcessIsSystemProcess |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1462 |
" |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1463 |
|
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1464 |
"Created: 17.4.1997 / 12:57:37 / stefan" |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1465 |
! |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1466 |
|
17407 | 1467 |
isUserProcess |
1468 |
"return true if aProcess is a user process." |
|
1469 |
||
1470 |
^ processGroupId ~~ 0 and:[id ~~ 0] |
|
1471 |
! |
|
1472 |
||
818 | 1473 |
nameOrId |
1474 |
"return a string to identify the process - either name or id" |
|
1475 |
||
1476 |
name notNil ifTrue:[^ name]. |
|
1477 |
^ id printString |
|
5675
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1478 |
! |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1479 |
|
9361 | 1480 |
parentProcess |
17244 | 1481 |
"answer my parent. |
1482 |
Notice: we do only keep the id here, to prevent the parentProcess from being |
|
1483 |
referenced (and therefore not garbage collected if it terminates)" |
|
9361 | 1484 |
|
14722 | 1485 |
ProcessorScheduler knownProcessesDo:[:p| |
17544 | 1486 |
p id = creatorId ifTrue:[^ p]. |
14443 | 1487 |
]. |
1488 |
^ nil. |
|
9361 | 1489 |
|
1490 |
" |
|
1491 |
Processor activeProcess parentProcess |
|
1492 |
" |
|
14443 | 1493 |
|
1494 |
"Modified: / 26-10-2012 / 13:15:55 / cg" |
|
9361 | 1495 |
! |
1496 |
||
5675
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1497 |
processGroupLeader |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1498 |
"answer the parent of this process group" |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1499 |
|
5681 | 1500 |
|processes leader next creatorId| |
5675
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1501 |
|
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1502 |
processes := ProcessorScheduler knownProcesses. |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1503 |
leader := processes detect:[:p| p id = processGroupId] ifNone:nil. |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1504 |
leader isNil ifTrue:[ |
14722 | 1505 |
leader := self. |
1506 |
[ |
|
1507 |
creatorId := leader creatorId. |
|
1508 |
next := processes detect:[:p| p id = creatorId |
|
1509 |
and:[p processGroupId = processGroupId]] |
|
1510 |
ifNone:nil. |
|
1511 |
] doWhile:[next notNil and:[leader := next. true]]. |
|
5675
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1512 |
]. |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1513 |
|
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1514 |
^ leader. |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1515 |
|
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1516 |
" |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1517 |
Processor activeProcess processGroupLeader |
5812
e23a3fdc75cb
already-dead is a proceedable error
Claus Gittinger <cg@exept.de>
parents:
5683
diff
changeset
|
1518 |
" |
e23a3fdc75cb
already-dead is a proceedable error
Claus Gittinger <cg@exept.de>
parents:
5683
diff
changeset
|
1519 |
! ! |
818 | 1520 |
|
699 | 1521 |
!Process methodsFor:'special'! |
1522 |
||
15964 | 1523 |
externalLookupPopIfEqual: lookupObject |
1524 |
"Called by method lookup MOP when an lookup context is to be unwound |
|
1525 |
to cleanup lookup stack" |
|
1526 |
lookupActivations first == lookupObject ifTrue:[ |
|
16562 | 1527 |
lookupActivations := lookupActivations second. |
15964 | 1528 |
]. |
1529 |
||
1530 |
"Created: / 04-10-2013 / 10:46:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1531 |
"Modified (comment): / 04-10-2013 / 12:08:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1532 |
! |
|
1533 |
||
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1534 |
millisecondDelay:millis |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1535 |
"suspend the current process for some time. |
16846 | 1536 |
Attention: |
17544 | 1537 |
If the receiver is a system process (i.e. scheduler or event dispatcher) |
1538 |
this blocks the whole Smalltalk for the time delta; |
|
1539 |
if it's a normal thread, only that thread is suspended." |
|
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1540 |
|
2636
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1541 |
(self isSystemProcess) ifTrue:[ |
17544 | 1542 |
OperatingSystem millisecondDelay:millis |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1543 |
] ifFalse:[ |
17544 | 1544 |
Delay waitForMilliseconds:millis |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1545 |
] |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1546 |
|
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1547 |
"Created: 16.12.1995 / 13:10:53 / cg" |
2636
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1548 |
"Modified: 17.4.1997 / 13:02:25 / stefan" |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1549 |
! |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1550 |
|
699 | 1551 |
trapRestrictedMethods:trap |
1552 |
"Allow/deny the execution of restricted methods. |
|
1553 |
Process specific method restriction is not implemented yet, so this call is |
|
1554 |
redirected to ObjectMemory and causes a system wide restriction. |
|
1555 |
||
1556 |
Notice: method restriction is a nonstandard feature, not supported |
|
1557 |
by other smalltalk implementations and not specified in the ANSI spec. |
|
1558 |
This is EXPERIMENTAL - and being evaluated for usability. |
|
1559 |
It may change or even vanish (if it shows to be not useful)." |
|
1560 |
||
1561 |
^ObjectMemory trapRestrictedMethods:trap |
|
1562 |
||
1563 |
" |
|
1564 |
Processor activeProcess trapRestrictedMethods:true |
|
1565 |
Processor activeProcess trapRestrictedMethods:false |
|
1566 |
" |
|
1567 |
||
1568 |
"Created: 8.11.1995 / 19:45:04 / stefan" |
|
1569 |
! |
|
1570 |
||
1571 |
uninterruptablyDo:aBlock |
|
14722 | 1572 |
"execute aBlock with interrupts blocked. |
699 | 1573 |
This does not prevent preemption by a higher priority processes |
1574 |
if any becomes runnable due to the evaluation of aBlock |
|
1575 |
(i.e. if a semaphore is signalled there)." |
|
1576 |
||
1577 |
"we must keep track of blocking-state if this is called nested" |
|
2302 | 1578 |
(OperatingSystem blockInterrupts) ifTrue:[ |
14722 | 1579 |
"/ already blocked |
1580 |
^ aBlock value |
|
2302 | 1581 |
]. |
699 | 1582 |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6322
diff
changeset
|
1583 |
^ aBlock ensure:[OperatingSystem unblockInterrupts] |
159 | 1584 |
! |
1585 |
||
699 | 1586 |
waitUntilSuspended |
1587 |
"wait until the receiver is suspended." |
|
1588 |
||
5377 | 1589 |
self isDead ifFalse:[ |
22175 | 1590 |
[ |
1591 |
"/ must check again - interrupt could have happened |
|
1592 |
"/ and process already terminated. |
|
1593 |
self isDead ifFalse:[ |
|
1594 |
suspendSemaphore isNil ifTrue:[ |
|
1595 |
suspendSemaphore := Semaphore name:'process suspend' |
|
1596 |
]. |
|
1597 |
suspendSemaphore wait |
|
1598 |
] |
|
1599 |
] valueUninterruptably |
|
5377 | 1600 |
] |
699 | 1601 |
|
22175 | 1602 |
"Modified: / 09-08-2017 / 11:55:51 / cg" |
699 | 1603 |
! |
1604 |
||
1605 |
waitUntilTerminated |
|
1606 |
"wait until the receiver is terminated. |
|
1607 |
This method allows another process to wait till the receiver finishes." |
|
1608 |
||
6774
6711472e6df4
oops - waitUntil terminated for a process that did not rune
penk
parents:
6739
diff
changeset
|
1609 |
self waitUntilTerminatedWithTimeout:nil |
1033 | 1610 |
|
1789 | 1611 |
" |
1612 |
|p| |
|
1613 |
||
6774
6711472e6df4
oops - waitUntil terminated for a process that did not rune
penk
parents:
6739
diff
changeset
|
1614 |
p := [100 timesRepeat:[1000 factorial]] forkAt:4. |
1789 | 1615 |
|
1616 |
Transcript showCR:'now waiting ...'. |
|
1617 |
p waitUntilTerminated. |
|
1618 |
Transcript showCR:'done.' |
|
1619 |
" |
|
1620 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1621 |
"Modified: 12.1.1997 / 00:40:59 / cg" |
699 | 1622 |
! |
1623 |
||
4735
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1624 |
waitUntilTerminatedWithTimeout:secondsOrNil |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1625 |
"wait until the receiver is terminated or (if non-nil) until |
14722 | 1626 |
the time period exired. |
13206
bffd4afb5be0
comment/format in: #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
13016
diff
changeset
|
1627 |
Returns true if a timeout occurred. |
8566 | 1628 |
This method allows another process to wait until the receiver finishes |
4735
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1629 |
(optionally) within some time." |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1630 |
|
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1631 |
|sema didTimeout| |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1632 |
|
10553 | 1633 |
didTimeout := false. |
1634 |
||
5377 | 1635 |
self isDead ifFalse:[ |
22175 | 1636 |
[ |
1637 |
"/ must check again - interrupt could have happened |
|
1638 |
"/ and process already terminated. |
|
1639 |
self isDead ifFalse:[ |
|
1640 |
sema := Semaphore name:'process termination'. |
|
1641 |
self addExitAction:[sema signal]. |
|
1642 |
didTimeout := (sema waitWithTimeout:secondsOrNil) isNil |
|
1643 |
] |
|
1644 |
] valueUninterruptably. |
|
5377 | 1645 |
]. |
10553 | 1646 |
^ didTimeout |
4735
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1647 |
|
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1648 |
" |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1649 |
|p| |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1650 |
|
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1651 |
p := [10 timesRepeat:[10000 factorial]] forkAt:4. |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1652 |
|
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1653 |
Transcript showCR:'now waiting ...'. |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1654 |
(p waitUntilTerminatedWithTimeout:2) ifTrue:[ |
22175 | 1655 |
Transcript showCR:'timeout occurred.' |
4735
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1656 |
] |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1657 |
" |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1658 |
|
22175 | 1659 |
"Modified: / 09-08-2017 / 11:55:56 / cg" |
4735
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1660 |
! |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1661 |
|
9059 | 1662 |
withHigherPriorityDo:aBlock |
1663 |
"execute aBlock at a higher priority." |
|
1664 |
||
1665 |
^ self withPriority:(prio + 1) do:aBlock |
|
1666 |
||
1667 |
" |
|
1668 |
Processor activeProcess withHigherPriorityDo:[3000 factorial] |
|
1669 |
" |
|
1670 |
! |
|
1671 |
||
699 | 1672 |
withLowerPriorityDo:aBlock |
1673 |
"execute aBlock at a lower priority. This can be used to perform |
|
1674 |
time-consuming operations at a more user-friendly priority." |
|
159 | 1675 |
|
699 | 1676 |
^ self withPriority:(prio - 1) do:aBlock |
1677 |
||
1678 |
" |
|
1679 |
Processor activeProcess withLowerPriorityDo:[3000 factorial] |
|
1680 |
" |
|
1681 |
! |
|
1682 |
||
1683 |
withPriority:aPrio do:aBlock |
|
1684 |
"execute aBlock at another priority. This can be used to perform |
|
1685 |
time-consuming operations at a more user-friendly priority, |
|
1686 |
or some critical action at a higher priority. Do not use too high |
|
1687 |
of a priority to avoid locking up the system (event processing takes place |
|
1688 |
at 24)" |
|
1689 |
||
1690 |
|oldprio| |
|
1691 |
||
1692 |
oldprio := prio. |
|
1693 |
self priority:aPrio. |
|
1694 |
||
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6322
diff
changeset
|
1695 |
^ aBlock ensure:[ |
14722 | 1696 |
self priority:oldprio |
699 | 1697 |
] |
1698 |
||
1699 |
" |
|
1700 |
Processor activeProcess withPriority:7 do:[3000 factorial] |
|
1701 |
" |
|
1702 |
"be careful - even ^C wont work until done: |
|
1703 |
Processor activeProcess withPriority:25 do:[3000 factorial] |
|
1704 |
" |
|
2839
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1705 |
! |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1706 |
|
4433 | 1707 |
withPriority:lowPrio to:highPrio do:aBlock |
1708 |
"execute aBlock at a priority range. This can be used to perform |
|
1709 |
time-consuming operations at a more user-friendly priority, |
|
1710 |
or some critical action at a higher priority. Do not use too high |
|
1711 |
of a priority to avoid locking up the system (event processing takes place |
|
1712 |
at 24)" |
|
1713 |
||
1714 |
|oldprio oldRange| |
|
1715 |
||
1716 |
oldprio := prio. |
|
1717 |
oldRange := priorityRange. |
|
1718 |
self priorityRange:(lowPrio to:highPrio). |
|
1719 |
||
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6322
diff
changeset
|
1720 |
^ aBlock ensure:[ |
14722 | 1721 |
self priorityRange:oldRange. |
1722 |
self priority:oldprio. |
|
4433 | 1723 |
] |
1724 |
||
1725 |
" |
|
1726 |
Processor activeProcess withPriority:7 to:8 do:[3000 factorial] |
|
1727 |
" |
|
1728 |
! |
|
1729 |
||
2839
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1730 |
withSystemBackgroundPriorityDo:aBlock |
14722 | 1731 |
"execute aBlock at system background priority. |
2839
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1732 |
This can be used to perform |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1733 |
background operations at a more user-friendly priority." |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1734 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1735 |
^ self withPriority:(Processor systemBackgroundPriority) do:aBlock |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1736 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1737 |
" |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1738 |
Processor activeProcess withSystemBackgroundPriorityDo:[3000 factorial] |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1739 |
" |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1740 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1741 |
"Created: 7.8.1997 / 12:56:23 / cg" |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1742 |
! |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1743 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1744 |
withUserBackgroundPriorityDo:aBlock |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1745 |
"execute aBlock at background priority. This can be used to perform |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1746 |
time-consuming operations at a more user-friendly priority." |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1747 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1748 |
^ self withPriority:(Processor userBackgroundPriority) do:aBlock |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1749 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1750 |
" |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1751 |
Processor activeProcess withUserBackgroundPriorityDo:[3000 factorial] |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1752 |
" |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1753 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1754 |
"Created: 6.8.1997 / 15:40:02 / cg" |
202 | 1755 |
! ! |
1756 |
||
5256 | 1757 |
!Process methodsFor:'startup'! |
116 | 1758 |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1759 |
imageRestart |
699 | 1760 |
"restart the process from the beginning. |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1761 |
This is sent by the ProcessorScheduler at image restart time, |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1762 |
to all restartable processes." |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1763 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1764 |
|savedGroupId| |
699 | 1765 |
|
1766 |
"/ ('restart process ' , id printString) errorPrintNL. |
|
1767 |
||
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1768 |
savedGroupId := processGroupId. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1769 |
|
14722 | 1770 |
(Processor newProcessFor:self withId:id) ifFalse:[ |
5450 | 1771 |
"for some reason, the Processor was unable to create |
1772 |
a VM process for me ...." |
|
699 | 1773 |
|
5450 | 1774 |
('Process [warning]: process ' , id printString , ' failed to restart.') errorPrintCR. |
1775 |
^ nil |
|
699 | 1776 |
]. |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1777 |
processGroupId := savedGroupId. |
699 | 1778 |
self resume |
1086 | 1779 |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1780 |
"Created: 28.10.1996 / 20:32:34 / cg" |
2130
b9e7e1cf98bd
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1781 |
"Modified: 10.1.1997 / 18:01:13 / cg" |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1782 |
! |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1783 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1784 |
restart |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1785 |
"restart the process from the beginning. |
21433 | 1786 |
This is only possible, if it's restartable." |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1787 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1788 |
restartable ifFalse:[ |
23016 | 1789 |
^ self proceedableError:'process is not restartable' |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1790 |
]. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1791 |
|
22693 | 1792 |
self interruptWith:[RestartProcessRequest raise] |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1793 |
|
21433 | 1794 |
"Modified: / 12-01-1997 / 00:54:32 / cg" |
1795 |
"Modified (comment): / 13-02-2017 / 20:29:07 / cg" |
|
22693 | 1796 |
"Modified: / 23-04-2018 / 14:01:40 / stefan" |
23016 | 1797 |
"Modified: / 24-05-2018 / 21:03:56 / Claus Gittinger" |
699 | 1798 |
! |
1799 |
||
116 | 1800 |
start |
159 | 1801 |
"start the process - this is sent by the VM to the process to get |
1802 |
the process up and running. |
|
329 | 1803 |
Sending #start to the process (instead of directly executing the startBlock) |
14722 | 1804 |
allows more flexible handling of processes, since anything that responds |
329 | 1805 |
to #start can be handled transparently by the VM then ..." |
159 | 1806 |
|
1807 |
|block| |
|
116 | 1808 |
|
24058 | 1809 |
(restartable ~~ true and:[startTimestamp notNil]) ifTrue:[ |
21333 | 1810 |
"is this artificial restriction useful ?" |
23016 | 1811 |
self proceedableError:'a process cannot be started twice'. |
21333 | 1812 |
^ self. |
1813 |
]. |
|
1814 |
||
1815 |
"/ |
|
1816 |
"/ just for your convenience ... |
|
1817 |
"/ |
|
1818 |
startTimestamp := Timestamp now. |
|
1819 |
name isNil ifTrue:[ |
|
1820 |
name := '(' , startBlock displayString , ')' |
|
1821 |
]. |
|
1822 |
||
1823 |
"save block for possible restart" |
|
1824 |
block := startBlock. |
|
24058 | 1825 |
"/ restartable ~~ true ifTrue:[ |
1826 |
"/ startBlock := nil |
|
1827 |
"/ ]. |
|
21333 | 1828 |
|
1829 |
[ |
|
21324 | 1830 |
"/ |
21333 | 1831 |
"/ block is the one which received the fork/newProcess some time ago... |
1832 |
"/ |
|
1833 |
self exceptionHandlerSet handleDo:block |
|
1834 |
] on:CaughtSignals do:[:ex | |
|
1835 |
"/ |
|
1836 |
"/ CaughtSignals: handle Process-Termination, Process-Restart and Abort |
|
1837 |
"/ |
|
1838 |
ex creator == RestartProcessRequest ifTrue:[ |
|
1839 |
ex restart |
|
21324 | 1840 |
]. |
21333 | 1841 |
ex return |
1842 |
] ensure:[ |
|
1843 |
self terminateNoSignal |
|
1844 |
]. |
|
1845 |
||
1846 |
"Modified: / 17-11-2001 / 16:45:32 / cg" |
|
1847 |
"Modified: / 31-01-2017 / 16:41:05 / stefan" |
|
23016 | 1848 |
"Modified: / 24-05-2018 / 21:04:12 / Claus Gittinger" |
24058 | 1849 |
"Modified: / 11-04-2019 / 14:56:09 / Stefan Vogel" |
1 | 1850 |
! ! |
1851 |
||
7263 | 1852 |
!Process methodsFor:'suspend & resume'! |
1 | 1853 |
|
5592 | 1854 |
abort |
14722 | 1855 |
"raise an AbortOperationRequest in the receiver process. |
1856 |
Most processes willing to handle this will return to some save state |
|
5592 | 1857 |
(typically, some kind of event loop). |
1858 |
If not handled, this will result in termination of the process." |
|
1859 |
||
1860 |
Processor activeProcess == self ifTrue:[ |
|
14722 | 1861 |
AbortOperationRequest raiseRequest |
5592 | 1862 |
] ifFalse:[ |
14722 | 1863 |
self interruptWith:[ |
1864 |
AbortOperationRequest raiseRequest |
|
1865 |
]. |
|
5592 | 1866 |
] |
6204
2bafef9151dd
class based exceptions - abortSignal;
Claus Gittinger <cg@exept.de>
parents:
5870
diff
changeset
|
1867 |
|
2bafef9151dd
class based exceptions - abortSignal;
Claus Gittinger <cg@exept.de>
parents:
5870
diff
changeset
|
1868 |
"Modified: / 16.11.2001 / 17:39:18 / cg" |
5592 | 1869 |
! |
1870 |
||
699 | 1871 |
resume |
1872 |
"resume the receiver process" |
|
1873 |
||
4002
341a896cb334
allow stopping a waiting process
Claus Gittinger <cg@exept.de>
parents:
3785
diff
changeset
|
1874 |
state == #stopped ifTrue:[ |
5450 | 1875 |
state := #run. |
4002
341a896cb334
allow stopping a waiting process
Claus Gittinger <cg@exept.de>
parents:
3785
diff
changeset
|
1876 |
]. |
699 | 1877 |
Processor resume:self |
1878 |
! |
|
1879 |
||
1880 |
resumeForSingleSend |
|
1881 |
"resume the receiver process, but only let it execute a single send." |
|
1882 |
||
1883 |
Processor resumeForSingleSend:self |
|
1884 |
! |
|
1885 |
||
326 | 1886 |
stop |
1887 |
"suspend the receiver process - will continue to run when a resume is sent. |
|
1888 |
A stopped process will not be resumed for interrupt processing." |
|
1889 |
||
11283 | 1890 |
self suspendWithState:#stopped. |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1891 |
|
3679 | 1892 |
"Modified: / 13.12.1995 / 13:22:58 / stefan" |
1893 |
"Modified: / 27.7.1998 / 23:37:15 / cg" |
|
326 | 1894 |
! |
1895 |
||
1 | 1896 |
suspend |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1897 |
"suspend the receiver process - it will continue to run when a resume is sent. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1898 |
Notice, that an interrupt will also resume the receiver, |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1899 |
so any waiting code should be prepared for premature return from |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1900 |
a suspend (see wait code in Semaphore). |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1901 |
Use #stop for a hard-suspend, which is not affected by interrupts." |
13 | 1902 |
|
1474 | 1903 |
self suspendWithState:#suspended |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1904 |
|
1474 | 1905 |
"Modified: 17.6.1996 / 14:41:34 / cg" |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1906 |
! |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1907 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1908 |
suspendWithState:aStateSymbol |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1909 |
"like suspend, this suspends the receiver process until a resume is sent. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1910 |
This sets the state to the argument, aStateSymbol, which is shown |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1911 |
in the ProcessMonitor (instead of #suspended). |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1912 |
(i.e. no new functionality, but a bit more debuggability) |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1913 |
Notice, that an interrupt will also resume the receiver, |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1914 |
so any waiting code should be prepared for premature return from |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1915 |
a suspend (see wait code in Semaphore). |
16312 | 1916 |
Use #stop for a hard-suspend, which is not affected by interrupts. |
1917 |
Should be called with interrupts disabled." |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1918 |
|
23038 | 1919 |
<resource: #skipInDebuggersWalkBack> |
1920 |
||
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1921 |
suspendSemaphore notNil ifTrue:[suspendSemaphore signalForAll]. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1922 |
suspendActions notNil ifTrue:[ |
23038 | 1923 |
|savedState| |
1924 |
||
1925 |
savedState := state. |
|
1926 |
state := #aboutToSuspend. |
|
1927 |
suspendActions do:[:action | action value]. |
|
1928 |
state ~~ #aboutToSuspend ifTrue:[ |
|
1929 |
"/ mhmh - one of the suspendActions lead to making me active again; |
|
1930 |
"/ bail out. |
|
1931 |
"/ This fixes the Semaphore was signalled, but process did not run error, |
|
1932 |
"/ which can happen when a process with a suspend action goes into a readWait, |
|
1933 |
"/ and the suspend action does a thread switch, and the readWait semaphore gets |
|
1934 |
"/ signalled before we come back here. Then the semaphore wakeup will have already |
|
1935 |
"/ place me back into the run state, so I should not go into a suspend below. |
|
1936 |
^ self. |
|
1937 |
]. |
|
1938 |
state := savedState. |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1939 |
]. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1940 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1941 |
" |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1942 |
this is a bit of a kludge: allow someone else to |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1943 |
set the state to something like #ioWait etc. |
19452 | 1944 |
In this case, do not set the receiver's state to #suspend. |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1945 |
(All of this to enhance the output of the process monitor ...) |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1946 |
" |
14722 | 1947 |
(state == #active |
1948 |
or:[state == #run |
|
4002
341a896cb334
allow stopping a waiting process
Claus Gittinger <cg@exept.de>
parents:
3785
diff
changeset
|
1949 |
or:[aStateSymbol == #stopped]]) ifTrue:[ |
23038 | 1950 |
state := aStateSymbol. |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1951 |
]. |
1 | 1952 |
Processor suspend:self |
23038 | 1953 |
|
1954 |
"Modified: / 30-05-2018 / 13:57:00 / Claus Gittinger" |
|
1 | 1955 |
! |
1956 |
||
1957 |
terminate |
|
14722 | 1958 |
"terminate the receiver process. |
1959 |
Termination is done by raising the terminateSignal in the receiver process, |
|
2689 | 1960 |
which can be caught. |
22693 | 1961 |
If the process is stopped, it will be resumed so that it can die. |
375 | 1962 |
All unwind actions and the exit-actions (if any) |
4415
dff1649c072c
resume the process when terminated.
Claus Gittinger <cg@exept.de>
parents:
4002
diff
changeset
|
1963 |
will be performed before the process is really terminated. |
dff1649c072c
resume the process when terminated.
Claus Gittinger <cg@exept.de>
parents:
4002
diff
changeset
|
1964 |
Notice, that the terminate actions are performed by the receiver, |
dff1649c072c
resume the process when terminated.
Claus Gittinger <cg@exept.de>
parents:
4002
diff
changeset
|
1965 |
at its current priority. Therefore, in case higher prio processes are |
dff1649c072c
resume the process when terminated.
Claus Gittinger <cg@exept.de>
parents:
4002
diff
changeset
|
1966 |
running, it may take any arbitrary time until the termination is eventually |
dff1649c072c
resume the process when terminated.
Claus Gittinger <cg@exept.de>
parents:
4002
diff
changeset
|
1967 |
done." |
10 | 1968 |
|
22693 | 1969 |
self terminateWithException:TerminateProcessRequest newException. |
21313 | 1970 |
|
1971 |
"Modified: / 24-08-1998 / 18:29:46 / cg" |
|
22693 | 1972 |
"Modified: / 23-04-2018 / 14:31:06 / stefan" |
1973 |
"Modified (comment): / 23-04-2018 / 15:40:43 / stefan" |
|
159 | 1974 |
! |
1975 |
||
4875 | 1976 |
terminateAllGUISubprocesses |
19452 | 1977 |
"terminate all the receiver's gui subprocesses and their children as well |
5683
3312d4d798dc
terminateAllGUISubprocesses no longer restricted to processGroup.
Stefan Vogel <sv@exept.de>
parents:
5681
diff
changeset
|
1978 |
(i.e. all processes which are offsprings of the receiver, except for |
4875 | 1979 |
the receiver itself)." |
1980 |
||
5377 | 1981 |
id isNil ifTrue:[ |
20808 | 1982 |
"/ problem: |
1983 |
"/ if receiver is already dead, its id is nil. |
|
1984 |
"/ children are found by looking for processes with a parentID identical to |
|
1985 |
"/ mine - ifNil, system processes are found, which is probably not what you |
|
1986 |
"/ want ... |
|
1987 |
"/ FIX: remember the id (or don't nil it when terminating) |
|
1988 |
"/ requires VM changes. |
|
1989 |
ProcessorScheduler invalidProcessSignal |
|
1990 |
raiseRequestWith:self |
|
1991 |
errorString:'process is already dead - cannot determine child processes'. |
|
1992 |
^ self |
|
5377 | 1993 |
]. |
4875 | 1994 |
ProcessorScheduler knownProcesses do:[:aProcess | |
21313 | 1995 |
(aProcess ~~ self and:[aProcess creatorId == id and:[aProcess isGUIProcess]]) ifTrue:[ |
1996 |
aProcess terminateWithAllGUISubprocesses |
|
1997 |
]. |
|
4875 | 1998 |
]. |
1999 |
||
14443 | 2000 |
"Created: / 28-10-1996 / 20:43:32 / cg" |
2001 |
"Modified: / 26-10-2012 / 13:16:35 / cg" |
|
21313 | 2002 |
"Modified: / 24-01-2017 / 17:38:10 / stefan" |
5812
e23a3fdc75cb
already-dead is a proceedable error
Claus Gittinger <cg@exept.de>
parents:
5683
diff
changeset
|
2003 |
! |
4875 | 2004 |
|
6783 | 2005 |
terminateAllSubprocessesInGroup |
2006 |
"terminate all subprocesses which have the receiver process as groupID, |
|
2007 |
and their group-children as well. |
|
19452 | 2008 |
(i.e. all processes in the receiver's process group, except for the receiver itself, |
6783 | 2009 |
and recursively oll of their group processes.)." |
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
2010 |
|
5377 | 2011 |
id isNil ifTrue:[ |
20808 | 2012 |
"/ problem: |
2013 |
"/ if receiver is already dead, its id is nil. |
|
2014 |
"/ children are found by looking for processes with a parentID identical to |
|
2015 |
"/ mine - ifNil, system processes are found, which is probably not what you |
|
2016 |
"/ want ... |
|
2017 |
"/ FIX: remember the id (or don't nil it when terminating) |
|
2018 |
"/ requires VM changes. |
|
2019 |
ProcessorScheduler invalidProcessSignal |
|
2020 |
raiseRequestWith:self |
|
2021 |
errorString:'process is already dead - cannot determine child processes'. |
|
2022 |
^ self |
|
5377 | 2023 |
]. |
9300 | 2024 |
self terminateAllSubprocessesInGroup:id |
2025 |
! |
|
2026 |
||
2027 |
terminateAllSubprocessesInGroup:aGroup |
|
2028 |
"terminate all subprocesses which have aGroup as groupID, |
|
2029 |
and their group-children as well. |
|
19452 | 2030 |
(i.e. all processes in the receiver's process group, except for the receiver itself, |
9300 | 2031 |
and recursively oll of their group processes.)." |
2032 |
||
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
2033 |
ProcessorScheduler knownProcesses do:[:aProcess | |
21313 | 2034 |
(aProcess ~~ self and:[aProcess processGroupId == aGroup]) ifTrue:[ |
2035 |
aProcess terminateWithAllSubprocessesInGroup |
|
2036 |
]. |
|
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
2037 |
]. |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2038 |
|
21313 | 2039 |
"Created: / 28-10-1996 / 20:43:32 / cg" |
2040 |
"Modified: / 03-11-1997 / 00:28:06 / cg" |
|
2041 |
"Modified: / 24-01-2017 / 17:42:33 / stefan" |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2042 |
! |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2043 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2044 |
terminateGroup |
14722 | 2045 |
"terminate the receiver with all of its created subprocesses |
19452 | 2046 |
that are in the receiver's process group." |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2047 |
|
5683
3312d4d798dc
terminateAllGUISubprocesses no longer restricted to processGroup.
Stefan Vogel <sv@exept.de>
parents:
5681
diff
changeset
|
2048 |
id isNil ifTrue:[ |
20808 | 2049 |
"/ problem: |
2050 |
"/ if receiver is already dead, its id is nil. |
|
2051 |
"/ children are found by looking for processes with a parentID identical to |
|
2052 |
"/ mine - ifNil, system processes are found, which is probably not what you |
|
2053 |
"/ want ... |
|
2054 |
"/ FIX: remember the id (or don't nil it when terminating) |
|
2055 |
"/ requires VM changes. |
|
2056 |
ProcessorScheduler invalidProcessSignal |
|
2057 |
raiseRequestWith:self |
|
2058 |
errorString:'process is already dead - cannot determine child processes'. |
|
2059 |
^ self |
|
5683
3312d4d798dc
terminateAllGUISubprocesses no longer restricted to processGroup.
Stefan Vogel <sv@exept.de>
parents:
5681
diff
changeset
|
2060 |
]. |
3312d4d798dc
terminateAllGUISubprocesses no longer restricted to processGroup.
Stefan Vogel <sv@exept.de>
parents:
5681
diff
changeset
|
2061 |
ProcessorScheduler knownProcesses do:[:aProcess | |
21313 | 2062 |
(aProcess ~~ self and:[aProcess processGroupId == id]) ifTrue:[ |
2063 |
aProcess terminate |
|
2064 |
]. |
|
5683
3312d4d798dc
terminateAllGUISubprocesses no longer restricted to processGroup.
Stefan Vogel <sv@exept.de>
parents:
5681
diff
changeset
|
2065 |
]. |
5812
e23a3fdc75cb
already-dead is a proceedable error
Claus Gittinger <cg@exept.de>
parents:
5683
diff
changeset
|
2066 |
self terminate |
21313 | 2067 |
|
2068 |
"Modified: / 24-01-2017 / 17:41:12 / stefan" |
|
5812
e23a3fdc75cb
already-dead is a proceedable error
Claus Gittinger <cg@exept.de>
parents:
5683
diff
changeset
|
2069 |
! |
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
2070 |
|
159 | 2071 |
terminateNoSignal |
2197 | 2072 |
"hard-terminate the receiver process without sending a terminateSignal |
375 | 2073 |
or performing any unwind-handling. |
2197 | 2074 |
However, exit-actions are performed. |
2075 |
This is useful in case of emergency, when a buggy terminationHandler |
|
2076 |
prevents you from getting a process to terminate." |
|
375 | 2077 |
|
2078 |
|block| |
|
159 | 2079 |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
2080 |
"/ this is treated like the final suspend |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
2081 |
suspendActions notNil ifTrue:[ |
5450 | 2082 |
[suspendActions isEmpty] whileFalse:[ |
2083 |
block := suspendActions removeFirst. |
|
2084 |
block value. |
|
2085 |
] |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
2086 |
]. |
375 | 2087 |
exitActions notNil ifTrue:[ |
5450 | 2088 |
[exitActions isEmpty] whileFalse:[ |
2089 |
block := exitActions removeFirst. |
|
2090 |
block value. |
|
2091 |
] |
|
375 | 2092 |
]. |
329 | 2093 |
suspendSemaphore notNil ifTrue:[suspendSemaphore signalForAll]. |
159 | 2094 |
Processor terminateNoSignal:self |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
2095 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
2096 |
"Modified: 13.12.1995 / 13:40:14 / stefan" |
2384 | 2097 |
"Modified: 12.2.1997 / 12:41:38 / cg" |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2098 |
! |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2099 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2100 |
terminateSubprocesses |
19751 | 2101 |
"terminate all the receiver's subprocesses |
19452 | 2102 |
(i.e. all processes in the receiver's process group, except for |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2103 |
the receiver itself)." |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2104 |
|
5377 | 2105 |
id isNil ifTrue:[ |
20808 | 2106 |
"/ problem: |
2107 |
"/ if receiver is already dead, its id is nil. |
|
2108 |
"/ children are found by looking for processes with a parentID identical to |
|
2109 |
"/ mine - ifNil, system processes are found, which is probably not what you |
|
2110 |
"/ want ... |
|
2111 |
"/ FIX: remember the id (or don't nil it when terminating) |
|
2112 |
"/ requires VM changes. |
|
2113 |
ProcessorScheduler invalidProcessSignal |
|
2114 |
raiseRequestWith:self |
|
2115 |
errorString:'process is already dead - cannot determine child processes'. |
|
2116 |
^ self |
|
10496
1198c42b85f5
Be conservative when setting helper processes of executeCommand:...
Stefan Vogel <sv@exept.de>
parents:
10436
diff
changeset
|
2117 |
]. |
1198c42b85f5
Be conservative when setting helper processes of executeCommand:...
Stefan Vogel <sv@exept.de>
parents:
10436
diff
changeset
|
2118 |
processGroupId == 0 ifTrue:[ |
20808 | 2119 |
ProcessorScheduler invalidProcessSignal |
2120 |
raiseWith:self errorString:'trying to terminate the system process group'. |
|
5377 | 2121 |
]. |
21313 | 2122 |
ProcessorScheduler knownProcesses do:[:eachProcess | |
2123 |
eachProcess ~~ self ifTrue:[ |
|
2124 |
|eachProcessGroupId| |
|
2125 |
||
2126 |
eachProcessGroupId := eachProcess processGroupId. |
|
2127 |
(eachProcessGroupId == processGroupId or:[eachProcessGroupId == id]) ifTrue:[ |
|
2128 |
eachProcess terminate |
|
2129 |
]. |
|
2130 |
]. |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2131 |
]. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2132 |
|
21313 | 2133 |
"Created: / 28-10-1996 / 20:41:49 / cg" |
2134 |
"Modified: / 26-08-1997 / 03:09:57 / cg" |
|
2135 |
"Modified: / 24-01-2017 / 17:35:25 / stefan" |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2136 |
! |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2137 |
|
4875 | 2138 |
terminateWithAllGUISubprocesses |
6783 | 2139 |
"terminate the receiver with all of its created gui subprocesses and their gui children." |
4875 | 2140 |
|
2141 |
self terminateAllGUISubprocesses. |
|
2142 |
self terminate |
|
2143 |
||
2144 |
"Modified: 28.10.1996 / 20:42:00 / cg" |
|
2145 |
"Created: 28.10.1996 / 20:44:07 / cg" |
|
2146 |
! |
|
2147 |
||
6783 | 2148 |
terminateWithAllSubprocessesInGroup |
2149 |
"terminate the receiver with |
|
19452 | 2150 |
all subprocesses which have the receiver's process ID as groupID, |
6783 | 2151 |
and their group-children as well. |
19751 | 2152 |
(i.e. the receiver plus all processes in the receiver's process group, |
6783 | 2153 |
and recursively all of their group processes)." |
2154 |
||
2155 |
self terminateAllSubprocessesInGroup. |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2156 |
self terminate |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2157 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2158 |
"Modified: 28.10.1996 / 20:42:00 / cg" |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2159 |
"Created: 28.10.1996 / 20:44:07 / cg" |
22693 | 2160 |
! |
2161 |
||
2162 |
terminateWithException:aTerminateException |
|
2163 |
"terminate the receiver process. |
|
2164 |
Termination is done by raising aTerminateException in the receiver process, |
|
2165 |
which can be caught. |
|
2166 |
If the process is stopped, it will be resumed so that it can die. |
|
2167 |
All unwind actions and the exit-actions (if any) |
|
2168 |
will be performed before the process is really terminated. |
|
2169 |
Notice, that the terminate actions are performed by the receiver, |
|
2170 |
at its current priority. Therefore, in case higher prio processes are |
|
2171 |
running, it may take any arbitrary time until the termination is eventually |
|
2172 |
done." |
|
2173 |
||
2174 |
|wasBlocked| |
|
2175 |
||
2176 |
Processor activeProcess == self ifTrue:[ |
|
2177 |
"suicide: terminating myself" |
|
2178 |
NoHandlerError handle:[:ex | |
|
2179 |
"unhandled TerminateProcessRequest is not an error - |
|
2180 |
the interrupt may be delivered before a |
|
2181 |
low priority process has set up the exception handler" |
|
2182 |
ex exception ~~ aTerminateException ifTrue:[ |
|
2183 |
ex reject. |
|
2184 |
]. |
|
2185 |
] do:[ |
|
2186 |
aTerminateException raise. |
|
2187 |
]. |
|
2188 |
self terminateNoSignal. |
|
2189 |
"not reached" |
|
2190 |
^ self. |
|
2191 |
]. |
|
2192 |
||
2193 |
"the receiver is terminated from another process" |
|
2194 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2195 |
[ |
|
2196 |
(state isNil or:[state == #dead]) ifTrue:[ |
|
2197 |
^ self. |
|
2198 |
]. |
|
2199 |
state == #osWait ifTrue:[ |
|
2200 |
"osWait processes cannot be interrupted" |
|
2201 |
self terminateNoSignal. |
|
2202 |
^ self. |
|
2203 |
]. |
|
2204 |
||
2205 |
self suspendedContext isNil ifTrue:[ |
|
2206 |
"if the receiver had no chance to execute yet, |
|
2207 |
it can be shot down without a signal" |
|
2208 |
self terminateNoSignal. |
|
2209 |
^ self |
|
2210 |
] |
|
2211 |
] ensure:[ |
|
2212 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts] |
|
2213 |
]. |
|
2214 |
||
2215 |
"register an interrupt action, so that I am terminating myself" |
|
2216 |
self interruptWith:[ |
|
2217 |
self terminateWithException:aTerminateException. |
|
2218 |
]. |
|
2219 |
"maybe I am stopped - resume so that I can die" |
|
2220 |
self resume. |
|
2221 |
||
2222 |
"Created: / 23-04-2018 / 14:29:34 / stefan" |
|
2223 |
"Modified (comment): / 23-04-2018 / 15:41:07 / stefan" |
|
1 | 2224 |
! ! |
2225 |
||
24238 | 2226 |
|
6739 | 2227 |
!Process methodsFor:'thread local storage'! |
2228 |
||
19387 | 2229 |
environment |
2230 |
"return the dictionary holding thread local variables, or nil if there are none" |
|
2231 |
||
2232 |
^ environment |
|
2233 |
! |
|
2234 |
||
2235 |
environment:aDictionary |
|
2236 |
"set the dictionary holding thread local variables, or nil if there are to be none" |
|
2237 |
||
2238 |
environment := aDictionary |
|
2239 |
! |
|
2240 |
||
7427 | 2241 |
environmentAt:aKey |
2242 |
"return the value of a thread local variable, or raise an error, if no such variable exists" |
|
2243 |
||
14722 | 2244 |
^ self |
2245 |
environmentAt:aKey |
|
2246 |
ifAbsent:[ |
|
2247 |
self errorKeyNotFound:aKey. |
|
2248 |
] |
|
7427 | 2249 |
! |
2250 |
||
2251 |
environmentAt:aKey ifAbsent:defaultValue |
|
2252 |
"return the value of a thread local variable, or the value of defaultValue if no such variable exists" |
|
6739 | 2253 |
|
2254 |
|val| |
|
2255 |
||
7427 | 2256 |
environment isNil ifTrue:[^ defaultValue value]. |
2257 |
val := environment at:aKey ifAbsent:[^ defaultValue value]. |
|
6739 | 2258 |
^ val value. |
2259 |
! |
|
2260 |
||
7427 | 2261 |
environmentAt:aKey put:aValue |
2262 |
"set the value of a thread local variable. Returns aValue" |
|
2263 |
||
2264 |
|var| |
|
2265 |
||
2266 |
environment isNil ifTrue:[ |
|
20067 | 2267 |
environment := IdentityDictionary new |
7427 | 2268 |
]. |
20067 | 2269 |
var := environment at:aKey ifAbsentPut:[ValueHolder new]. |
7427 | 2270 |
var value:aValue. |
2271 |
^ aValue |
|
2272 |
! |
|
2273 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
2274 |
environmentIncludesKey:aKey |
19388 | 2275 |
"true if there is a thread local variable, false if no such variable exists" |
2276 |
||
20067 | 2277 |
^ environment notNil and:[environment includesKey:aKey] |
19388 | 2278 |
! |
2279 |
||
19377 | 2280 |
stderr |
2281 |
"the processes stderr. |
|
2282 |
By default, this is Stderr, but it can be overwritten |
|
2283 |
(for example to redirect a thread's error output to some other place" |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
2284 |
|
19377 | 2285 |
^ self environmentAt:#Stderr ifAbsent:Stderr |
2286 |
||
2287 |
" |
|
22183 | 2288 |
Processor activeProcess stderr |
19377 | 2289 |
" |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
2290 |
|
19377 | 2291 |
" |
2292 |
|out sema| |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
2293 |
|
19377 | 2294 |
out := WriteStream on:''. |
2295 |
sema := Semaphore new. |
|
2296 |
[ |
|
22183 | 2297 |
Processor activeProcess environmentAt:#Stderr put:out. |
2298 |
'hello world' errorPrintCR. |
|
2299 |
sema signal. |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
2300 |
] fork. |
19377 | 2301 |
sema wait. |
2302 |
Transcript showCR:('output was: ''',out contents,''''). |
|
2303 |
" |
|
2304 |
! |
|
2305 |
||
2306 |
stdin |
|
2307 |
"the processes stdin. |
|
2308 |
By default, this is Stdin, but it can be overwritten |
|
2309 |
(for example to redirect a thread's input from some other place" |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
2310 |
|
19377 | 2311 |
^ self environmentAt:#Stdin ifAbsent:Stdin |
2312 |
! |
|
2313 |
||
2314 |
stdout |
|
2315 |
"the processes stdout. |
|
2316 |
By default, this is Stdout, but it can be overwritten |
|
2317 |
(for example to redirect a thread's output to some other place" |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
2318 |
|
19377 | 2319 |
^ self environmentAt:#Stdout ifAbsent:Stdout |
2320 |
! |
|
2321 |
||
7427 | 2322 |
threadVariableValueOf:aKey |
20682 | 2323 |
"return the value of a thread local variable, |
2324 |
or nil if no such variable exists" |
|
7427 | 2325 |
|
2326 |
^ self environmentAt:aKey ifAbsent:nil |
|
16047 | 2327 |
|
2328 |
" |
|
2329 |
see example in withThreadVariable:boundTo:do: |
|
2330 |
" |
|
7427 | 2331 |
! |
2332 |
||
19377 | 2333 |
transcript |
2334 |
"the processes transcript. |
|
2335 |
By default, this is Transcript, but it can be overwritten |
|
2336 |
(for example to redirect a thread's output to some other place" |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
2337 |
|
19380 | 2338 |
^ self environmentAt:#Transcript ifAbsent:[Transcript] |
19377 | 2339 |
! |
2340 |
||
19387 | 2341 |
withThreadLocalVariables:aDictionary do:aBlock |
2342 |
"evaluate a block with threadLocalVariables from aDictionary; |
|
2343 |
restore the old bindings afterwards." |
|
2344 |
||
2345 |
|oldEnv result| |
|
2346 |
||
2347 |
oldEnv := environment. |
|
2348 |
||
2349 |
[ |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
2350 |
environment := aDictionary. |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
2351 |
result := aBlock value. |
19387 | 2352 |
] ensure:[ |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
2353 |
environment := oldEnv. |
19387 | 2354 |
]. |
2355 |
^ result |
|
2356 |
! |
|
2357 |
||
6739 | 2358 |
withThreadVariable:variableNameSymbol boundTo:aValue do:aBlock |
7427 | 2359 |
"evaluate a block with the threadLocalVariable being bound to aValue; |
2360 |
undo the variable binding afterwards." |
|
2361 |
||
23050 | 2362 |
|var oldValue| |
6739 | 2363 |
|
2364 |
environment isNil ifTrue:[ |
|
20682 | 2365 |
environment := IdentityDictionary new |
6739 | 2366 |
]. |
2367 |
var := environment at:variableNameSymbol ifAbsent:nil. |
|
2368 |
var isNil ifTrue:[ |
|
20682 | 2369 |
var := ValueHolder new. |
2370 |
environment at:variableNameSymbol put:var. |
|
6739 | 2371 |
]. |
2372 |
||
2373 |
oldValue := var value. |
|
23050 | 2374 |
^ [ |
20682 | 2375 |
var value:aValue. |
23050 | 2376 |
aBlock value. |
6739 | 2377 |
] ensure:[ |
20682 | 2378 |
oldValue isNil |
2379 |
ifTrue:[ environment removeKey:variableNameSymbol] |
|
2380 |
ifFalse:[ var value:oldValue ] |
|
6739 | 2381 |
]. |
16047 | 2382 |
|
2383 |
" |
|
2384 |
|printIt| |
|
2385 |
||
20682 | 2386 |
printIt := [ |
2387 |
Transcript |
|
2388 |
showCR:'foo is now ', |
|
2389 |
(Processor activeProcess threadVariableValueOf:#foo) printString |
|
2390 |
]. |
|
16047 | 2391 |
|
2392 |
Processor activeProcess |
|
20682 | 2393 |
withThreadVariable:#foo |
2394 |
boundTo:1234 |
|
2395 |
do:[ |
|
2396 |
printIt value. |
|
2397 |
Processor activeProcess |
|
2398 |
withThreadVariable:#foo |
|
2399 |
boundTo:2345 |
|
2400 |
do:[ |
|
2401 |
printIt value |
|
2402 |
]. |
|
2403 |
] |
|
16047 | 2404 |
" |
23050 | 2405 |
|
2406 |
"Modified: / 05-06-2018 / 16:41:11 / Stefan Vogel" |
|
6739 | 2407 |
! ! |
2408 |
||
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
2409 |
!Process class methodsFor:'documentation'! |
159 | 2410 |
|
19293 | 2411 |
version |
2412 |
^ '$Header$' |
|
2413 |
! |
|
2414 |
||
13398 | 2415 |
version_CVS |
19292 | 2416 |
^ '$Header$' |
12764
c3da6be46ff1
use _MAX_INT instead of 0x3fffffff in primitive code when generating SmallIntegers
Stefan Vogel <sv@exept.de>
parents:
11416
diff
changeset
|
2417 |
! |
c3da6be46ff1
use _MAX_INT instead of 0x3fffffff in primitive code when generating SmallIntegers
Stefan Vogel <sv@exept.de>
parents:
11416
diff
changeset
|
2418 |
|
13398 | 2419 |
version_SVN |
15964 | 2420 |
^ '$ Id: Process.st 10643 2011-06-08 21:53:07Z vranyj1 $' |
159 | 2421 |
! ! |
6774
6711472e6df4
oops - waitUntil terminated for a process that did not rune
penk
parents:
6739
diff
changeset
|
2422 |
|
15117 | 2423 |
|
699 | 2424 |
Process initialize! |