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