author | Claus Gittinger <cg@exept.de> |
Wed, 10 Apr 2019 09:31:03 +0200 | |
changeset 24051 | f531b38415db |
parent 23258 | 1d65d1a0af5d |
child 24058 | 5ae2c27577c1 |
permissions | -rw-r--r-- |
22693 | 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 |
|
23050 | 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 |
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
582 |
"return the processcreators id. |
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. |
|
647 |
anInterval notNil ifTrue:[ |
|
16562 | 648 |
lowPri := priorityRange start. |
649 |
hiPri := priorityRange stop. |
|
650 |
(newPrio := prio) isNil ifTrue:[ |
|
651 |
newPrio := lowPri |
|
652 |
] ifFalse:[ |
|
653 |
prio < lowPri ifTrue:[ |
|
654 |
newPrio := lowPri |
|
655 |
] ifFalse:[ |
|
656 |
prio > hiPri ifTrue:[ |
|
657 |
newPrio := hiPri |
|
658 |
]. |
|
659 |
]. |
|
660 |
]. |
|
661 |
newPrio ~~ prio ifTrue:[ |
|
662 |
self priority:newPrio |
|
663 |
] |
|
9084 | 664 |
]. |
3679 | 665 |
|
3723 | 666 |
"Modified: / 3.8.1998 / 22:56:05 / cg" |
3679 | 667 |
! |
668 |
||
1529
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
669 |
processGroupId |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
670 |
"return the processes processGroup id. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
671 |
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
|
672 |
as the processGroup id. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
673 |
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
|
674 |
group members are terminated together. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
675 |
|
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
676 |
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
|
677 |
killed when the parent terminates (windowgroup processes do this)." |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
678 |
|
1530
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
679 |
^ processGroupId |
1529
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
680 |
|
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
681 |
"Created: 8.7.1996 / 13:47:47 / cg" |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
682 |
! |
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 |
processGroupId:aGroupLeadersProcessID |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
685 |
"set the processes processGroup id. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
686 |
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
|
687 |
as the processGroup id. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
688 |
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
|
689 |
group members are terminated together. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
690 |
|
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
691 |
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
|
692 |
killed when the parent terminates (windowgroup processes do this)." |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
693 |
|
1530
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
694 |
processGroupId := aGroupLeadersProcessID |
1529
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
695 |
|
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
696 |
"Created: 8.7.1996 / 13:47:53 / cg" |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
697 |
! |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
698 |
|
818 | 699 |
restartable:aBoolean |
700 |
"set/clear, the restartable flag. |
|
701 |
Restartable processes will automatically be restarted by the |
|
14722 | 702 |
ProcessorScheduler upon image restart. |
818 | 703 |
Others have to be restarted manually." |
704 |
||
705 |
startBlock isNil ifTrue:[ |
|
23016 | 706 |
self proceedableError:'cannot be made restartable when already started'. |
707 |
^ self |
|
818 | 708 |
]. |
709 |
restartable := aBoolean |
|
710 |
||
23016 | 711 |
"Modified: / 23-12-1995 / 18:38:32 / cg" |
712 |
"Modified: / 24-05-2018 / 21:04:04 / Claus Gittinger" |
|
818 | 713 |
! |
714 |
||
715 |
singleStep:aBoolean |
|
716 |
singleStepping := aBoolean |
|
717 |
! |
|
718 |
||
719 |
startBlock |
|
720 |
"return the processes startup-block" |
|
721 |
||
722 |
^ startBlock |
|
723 |
! |
|
724 |
||
21326 | 725 |
startTimestamp |
726 |
"return the processes' start time" |
|
727 |
||
728 |
startTimestamp notNil ifTrue:[ |
|
729 |
^ startTimestamp |
|
730 |
]. |
|
731 |
"/ the very first system process has no starttime set |
|
732 |
startTimestamp := Smalltalk imageStartTime. |
|
733 |
^ startTimestamp |
|
734 |
! |
|
735 |
||
818 | 736 |
state |
737 |
"return a symbol describing the processes state" |
|
738 |
||
739 |
^ state |
|
740 |
! |
|
741 |
||
742 |
state:aSymbol |
|
743 |
"set the state - only to be used from scheduler" |
|
744 |
||
745 |
state := aSymbol |
|
746 |
! |
|
747 |
||
748 |
suspendedContext |
|
14722 | 749 |
"return the processes suspended context |
818 | 750 |
- this is the context from which a process switch into the scheduler |
20251 | 751 |
or another process occurred. |
5088 | 752 |
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
|
753 |
had no chance to run yet, nil is returned. |
818 | 754 |
Typically, only the debugger is interested in this one." |
755 |
||
756 |
%{ /* NOCONTEXT */ |
|
757 |
OBJ i; |
|
758 |
||
1133 | 759 |
if (__isSmallInteger(i = __INST(id))) { |
20251 | 760 |
RETURN (__threadContext(__intVal(i))); |
818 | 761 |
} |
762 |
%}. |
|
763 |
^ nil |
|
764 |
! ! |
|
765 |
||
766 |
!Process methodsFor:'accessing-change notifications'! |
|
767 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
768 |
addExitAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
769 |
"add aBlock to the processes exit actions. |
5088 | 770 |
This block will be evaluated right before the process dies, |
771 |
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
|
772 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
773 |
exitActions isNil ifTrue:[ |
5450 | 774 |
exitActions := OrderedCollection new |
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
775 |
]. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
776 |
exitActions add:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
777 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
778 |
"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
|
779 |
! |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
780 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
781 |
addSuspendAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
782 |
"add aBlock to the processes suspend actions. |
5088 | 783 |
This block will be evaluated when a process gets suspended. |
14722 | 784 |
You may ask what that is useful for - it is useful to flush |
5088 | 785 |
buffered graphic commands of a GUI process (i.e. to force xlib |
786 |
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
|
787 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
788 |
suspendActions isNil ifTrue:[ |
5450 | 789 |
suspendActions := OrderedCollection new |
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
790 |
]. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
791 |
suspendActions add:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
792 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
793 |
"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
|
794 |
"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
|
795 |
! |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
796 |
|
699 | 797 |
emergencySignalHandler |
798 |
"return the emergencySignalHandler block. |
|
799 |
See Signal>>documentation for more info." |
|
800 |
||
801 |
^ emergencySignalHandler |
|
802 |
! |
|
803 |
||
804 |
emergencySignalHandler:aOneArgBlock |
|
805 |
"set the emergencySignalHandler block. |
|
806 |
See Signal>>documentation for more info." |
|
807 |
||
808 |
emergencySignalHandler := aOneArgBlock |
|
809 |
! |
|
810 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
811 |
removeAllExitActions |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
812 |
"remove all exit actions." |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
813 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
814 |
exitActions := nil. |
699 | 815 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
816 |
"Created: 12.1.1997 / 00:36:02 / cg" |
699 | 817 |
! |
818 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
819 |
removeAllSuspendActions |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
820 |
"remove all suspend actions." |
699 | 821 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
822 |
suspendActions := nil. |
699 | 823 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
824 |
"Created: 12.1.1997 / 00:36:16 / cg" |
13016 | 825 |
! |
826 |
||
827 |
removeExitAction:anExitAction ifAbsent:exceptionBlock |
|
828 |
"remove the identical exitAction; if found, remove and return it; |
|
829 |
if not, return the value from evaluating exceptionBlock" |
|
830 |
||
831 |
exitActions notNil ifTrue:[ |
|
14722 | 832 |
^ exitActions removeIdentical:anExitAction ifAbsent:exceptionBlock. |
13016 | 833 |
]. |
834 |
^ exceptionBlock value. |
|
818 | 835 |
! ! |
699 | 836 |
|
818 | 837 |
!Process methodsFor:'accessing-stack'! |
699 | 838 |
|
839 |
maximumStackSize |
|
14722 | 840 |
"returns the processes stack limit - i.e. the process will be |
699 | 841 |
interrupted with a recursionSignal-raise, if it ever |
842 |
needs more stack (in bytes) than this number" |
|
843 |
||
844 |
%{ /* NOCONTEXT */ |
|
19294 | 845 |
extern INT __threadMaxStackSize(); |
699 | 846 |
OBJ i; |
847 |
||
1133 | 848 |
if (__isSmallInteger(i = __INST(id))) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
849 |
RETURN( __MKINT(__threadMaxStackSize(__intVal(i))) ); |
699 | 850 |
} |
851 |
%}. |
|
852 |
^ nil |
|
853 |
! |
|
854 |
||
855 |
setMaximumStackSize:limit |
|
856 |
"sets the processes stack limit - i.e. the process will be |
|
857 |
interrupted with a recursionSignal-raise, if it ever |
|
858 |
needs more stack (in bytes) than this number. |
|
859 |
Returns the old value." |
|
860 |
||
861 |
%{ /* NOCONTEXT */ |
|
19294 | 862 |
extern INT __threadSetMaxStackSize(int, unsigned INT); |
699 | 863 |
OBJ i; |
864 |
||
14722 | 865 |
if (__isSmallInteger(i = __INST(id)) |
699 | 866 |
&& __isSmallInteger(limit) ) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
867 |
RETURN ( __MKINT(__threadSetMaxStackSize(__intVal(i), __intVal(limit))) ); |
699 | 868 |
} |
869 |
%}. |
|
870 |
^ nil |
|
871 |
! |
|
872 |
||
712
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
873 |
setStackInitialSize:initial increment:increment safe:safe |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
874 |
"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
|
875 |
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
|
876 |
|
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
877 |
%{ /* NOCONTEXT */ |
19294 | 878 |
extern INT __threadSetJunkSizes(int, unsigned INT, unsigned INT, unsigned INT); |
19296 | 879 |
|
712
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
880 |
OBJ i; |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
881 |
|
1133 | 882 |
if (__isSmallInteger(i = __INST(id)) |
712
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
883 |
&& __isSmallInteger(initial) |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
884 |
&& __isSmallInteger(increment) |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
885 |
&& __isSmallInteger(safe)) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
886 |
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
|
887 |
} |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
888 |
%}. |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
889 |
^ false |
699 | 890 |
! ! |
891 |
||
892 |
!Process methodsFor:'interrupts'! |
|
893 |
||
2725
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
894 |
blockInterrupts |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
895 |
"disable interrupt processing for the receiver process |
14722 | 896 |
- 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
|
897 |
soon as interrupts are reenabled via unblockInterrupts. |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
898 |
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
|
899 |
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
|
900 |
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
|
901 |
This is similar to OperatingSystem>>blockInterrupts, but only |
14722 | 902 |
affects interrupts for the receiver process |
2725
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
903 |
(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
|
904 |
|
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
905 |
|disabledBefore| |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
906 |
|
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
907 |
disabledBefore := interruptsDisabled. |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
908 |
interruptsDisabled := true. |
22326 | 909 |
^ disabledBefore |
2726 | 910 |
|
911 |
" |
|
912 |
|p1| |
|
913 |
||
914 |
p1 := [ |
|
22326 | 915 |
Transcript showCR:'disabled ...'. |
916 |
Transcript showCR:Processor activeProcess blockInterrupts. |
|
917 |
Transcript showCR:'busy ...'. |
|
918 |
Delay waitForSeconds:10. |
|
919 |
Transcript showCR:'enabled ...'. |
|
920 |
Processor activeProcess unblockInterrupts. |
|
921 |
] forkAt:9. |
|
2726 | 922 |
|
923 |
p1 interruptWith:[Transcript showCR:'interrupted']. |
|
924 |
" |
|
22326 | 925 |
|
926 |
"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
|
927 |
! |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
928 |
|
5491 | 929 |
hasInterruptActions |
930 |
"return true, if there are any interrupt actions to evaluate |
|
931 |
(i.e. if the receiver has been interrupted)." |
|
932 |
||
8544
732ed0a3d7ca
use #~~ instead of #> for speed
Stefan Vogel <sv@exept.de>
parents:
8495
diff
changeset
|
933 |
^ interruptActions size ~~ 0 |
5491 | 934 |
! |
935 |
||
699 | 936 |
interruptWith:aBlock |
937 |
"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
|
938 |
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
|
939 |
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
|
940 |
IFF its priority is higher than the current processes priority. |
22628 | 941 |
Otherwise, it will remain suspended, until its time comes. |
942 |
||
943 |
aBlock is evaluated with an optional argument: the context, that has been |
|
944 |
interrupted." |
|
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
945 |
|
21448 | 946 |
Processor activeProcess == self ifTrue:[ |
21447 | 947 |
aBlock value |
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
948 |
] ifFalse:[ |
21448 | 949 |
self isDead ifTrue:[ |
21463 | 950 |
"/ trying to register interrupt for dead process. |
951 |
^ self. |
|
21448 | 952 |
]. |
21447 | 953 |
self addInterruptAction:aBlock. |
954 |
Processor scheduleForInterrupt:self. |
|
2724 | 955 |
]. |
8613
b74b646a830b
no, last change leads to a blocking Debugger
Claus Gittinger <cg@exept.de>
parents:
8591
diff
changeset
|
956 |
|
21447 | 957 |
" |
958 |
Processor timeoutHandlerProcess interruptWith:[Transcript showCR:Processor activeProcess]. |
|
959 |
||
960 |
|p| |
|
961 |
p := [] fork. |
|
962 |
p waitUntilTerminated. |
|
963 |
p interruptWith:[Transcript showCR:Processor activeProcess]. |
|
964 |
" |
|
965 |
||
966 |
"Modified: / 12-01-1997 / 00:52:05 / cg" |
|
21463 | 967 |
"Modified: / 16-02-2017 / 18:09:38 / stefan" |
22628 | 968 |
"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
|
969 |
! |
699 | 970 |
|
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
971 |
onResumeDo:aBlock |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
972 |
"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
|
973 |
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
|
974 |
(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
|
975 |
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
|
976 |
when it awakes." |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
977 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
978 |
self addInterruptAction:aBlock. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
979 |
Processor scheduleInterruptActionsOf:self. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
980 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
981 |
"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
|
982 |
"Modified: 8.3.1996 / 13:01:21 / cg" |
2839
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
983 |
! |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
984 |
|
2857
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
985 |
stepInterruptHandler:anObject |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
986 |
"set the handler for stepInterrupts occurring in the receiver process. |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
987 |
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
|
988 |
stepInterrupts. Returns the previous handler. |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
989 |
Not for general use." |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
990 |
|
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
991 |
%{ /* NOCONTEXT */ |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
992 |
extern OBJ __threadStepInterruptHandler(); |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
993 |
|
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
994 |
RETURN( __threadStepInterruptHandler(anObject) ); |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
995 |
%} |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
996 |
! |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
997 |
|
2839
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
998 |
unblockInterrupts |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
999 |
"enable interrupt processing for the receiver process |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1000 |
- if any interrupts are pending, these will be handled immediately. |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1001 |
When unblocking interrupts, take care of nested block/unblock |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1002 |
calls - you should only unblock after a blockcall if they where |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1003 |
really not blocked before. |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1004 |
This is similar to OperatingSystem>>unblockInterrupts, but only |
14722 | 1005 |
affects interrupts for the receiver process |
2839
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1006 |
(i.e. those which are installed via #interruptWith:)" |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1007 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1008 |
interruptsDisabled := false. |
21008 | 1009 |
(interruptActions size ~~ 0 and:[Processor activeProcess == self]) ifTrue:[ |
1010 |
self interrupt. |
|
2839
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1011 |
] |
699 | 1012 |
! ! |
1013 |
||
21447 | 1014 |
!Process methodsFor:'interrupts-private'! |
1015 |
||
1016 |
addInterruptAction:aBlock |
|
1017 |
"make the receiver evaluate aBlock when resumed/interrupted. |
|
1018 |
The name is somewhat misleading (actually, its historic): |
|
1019 |
the block is also evaluated on resume." |
|
1020 |
||
1021 |
|wasBlocked| |
|
1022 |
||
1023 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1024 |
interruptActions isNil ifTrue:[ |
|
1025 |
interruptActions := OrderedCollection with:aBlock. |
|
1026 |
] ifFalse:[ |
|
1027 |
interruptActions addFirst:aBlock. |
|
1028 |
]. |
|
1029 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1030 |
! |
|
1031 |
||
1032 |
evaluateInterruptActionsWithContext:aContext |
|
1033 |
"evaluate my interrupt-actions." |
|
1034 |
||
22326 | 1035 |
|wasBlocked| |
1036 |
||
1037 |
wasBlocked := OperatingSystem blockInterrupts. |
|
21668 | 1038 |
[interruptActions notEmptyOrNil] whileTrue:[ |
22326 | 1039 |
|action| |
1040 |
||
21668 | 1041 |
action := interruptActions removeFirst. |
1042 |
interruptActions isEmpty ifTrue:[ |
|
1043 |
interruptActions := nil |
|
1044 |
]. |
|
1045 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
22326 | 1046 |
action valueWithOptionalArgument:aContext. |
1047 |
OperatingSystem blockInterrupts. |
|
21447 | 1048 |
]. |
22326 | 1049 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1050 |
||
1051 |
"Modified: / 25-10-2017 / 17:45:46 / stefan" |
|
21447 | 1052 |
! |
1053 |
||
1054 |
forceInterruptOnReturnOf:aContext |
|
1055 |
"helper entry for debugger. Force a stepInterrupt whenever aContext |
|
1056 |
returns either directly or via an unwind." |
|
1057 |
||
1058 |
aContext markForInterruptOnUnwind. |
|
1059 |
%{ |
|
1060 |
OBJ i; |
|
1061 |
||
1062 |
if (__isSmallInteger(i = __INST(id))) { |
|
1063 |
__threadContextStepInterrupt(__intVal(i), 1); |
|
1064 |
} |
|
1065 |
%} |
|
1066 |
||
1067 |
! |
|
1068 |
||
1069 |
interrupt |
|
1070 |
"evaluate my interrupt-actions. |
|
1071 |
The process will go back to where it got interrupted |
|
1072 |
after doing this. |
|
1073 |
||
1074 |
This is also sent by the VM." |
|
1075 |
||
1076 |
interruptActions size ~~ 0 ifTrue:[ |
|
1077 |
self evaluateInterruptActionsWithContext:thisContext sender. |
|
1078 |
]. |
|
1079 |
! |
|
1080 |
||
1081 |
interruptedIn:aContext |
|
1082 |
"evaluate my interrupt-actions. |
|
1083 |
This is indirectly called by the VM, when some #interruptWith: action |
|
1084 |
was scheduled for the process, and the process is resumed. |
|
1085 |
The process will go back to where it got interrupted after doing this." |
|
1086 |
||
1087 |
"/ the returned value here has a subtle effect: |
|
1088 |
"/ if false, the interrupt is assumed to be not taken, |
|
1089 |
"/ and will be redelivered. |
|
1090 |
||
22326 | 1091 |
interruptsDisabled ifTrue:[ |
21447 | 1092 |
"/ no, I don't want interrupts right now; |
1093 |
"/ try again later. |
|
1094 |
^ false |
|
1095 |
]. |
|
1096 |
||
1097 |
"/ I tend to disable interrupts, while processing interrupt actions; |
|
1098 |
"/ however, this leads to a blocking Debugger sometimes (scroll). |
|
1099 |
"/ [ |
|
1100 |
"/ interruptsDisabled := true. |
|
1101 |
self evaluateInterruptActionsWithContext:aContext. |
|
1102 |
"/ ] ensure:[ |
|
1103 |
"/ interruptsDisabled := false. |
|
1104 |
"/ ]. |
|
1105 |
^ true |
|
1106 |
||
22326 | 1107 |
"Created: / 18-10-1996 / 20:43:39 / cg" |
1108 |
"Modified: / 25-10-2017 / 18:04:01 / stefan" |
|
21447 | 1109 |
! ! |
1110 |
||
699 | 1111 |
!Process methodsFor:'monitoring'! |
1112 |
||
1113 |
numberOfStackBoundaryHits |
|
1114 |
"internal monitoring only - will vanish" |
|
1115 |
||
1116 |
%{ /* NOCONTEXT */ |
|
19294 | 1117 |
extern INT __threadNumberOfStackBoundaryHits(); |
1118 |
INT n; |
|
699 | 1119 |
OBJ i; |
159 | 1120 |
|
1133 | 1121 |
if (__isSmallInteger(i = __INST(id))) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
1122 |
n = __threadNumberOfStackBoundaryHits(__intVal(i)); |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
1123 |
n &= _MAX_INT; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
1124 |
RETURN( __mkSmallInteger(n) ); |
699 | 1125 |
} |
1126 |
%}. |
|
1127 |
^ nil |
|
1128 |
! |
|
1129 |
||
1130 |
numberOfStackSegments |
|
1131 |
"return the processes number of stack segments currently used. |
|
1132 |
This method is for monitoring purposes only - it may vanish." |
|
1133 |
||
1134 |
%{ /* NOCONTEXT */ |
|
19297 | 1135 |
extern int __threadStackSegments(); |
699 | 1136 |
OBJ i; |
1137 |
||
1133 | 1138 |
if (__isSmallInteger(i = __INST(id))) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
1139 |
RETURN( __mkSmallInteger((INT)__threadStackSegments(__intVal(i))) ); |
699 | 1140 |
} |
1141 |
%}. |
|
1142 |
^ nil |
|
1143 |
! |
|
1144 |
||
1145 |
totalStackSize |
|
1146 |
"return the processes maximum used stack size. |
|
1147 |
This method is for monitoring purposes only - it may vanish." |
|
1148 |
||
1149 |
%{ /* NOCONTEXT */ |
|
19294 | 1150 |
extern INT __threadTotalStackSize(); |
699 | 1151 |
OBJ i; |
1152 |
||
1133 | 1153 |
if (__isSmallInteger(i = __INST(id))) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
1154 |
RETURN( __MKINT(__threadTotalStackSize(__intVal(i))) ); |
699 | 1155 |
} |
1156 |
%}. |
|
1157 |
^ nil |
|
1158 |
! |
|
1159 |
||
1160 |
usedStackSize |
|
1161 |
"Return the processes current stack size. |
|
1162 |
This method is for monitoring purposes only - it may vanish." |
|
1163 |
||
1164 |
%{ /* NOCONTEXT */ |
|
14724 | 1165 |
extern unsigned INT __threadUsedStackSize(); |
699 | 1166 |
OBJ i; |
1167 |
||
1133 | 1168 |
if (__isSmallInteger(i = __INST(id))) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
1169 |
RETURN( __MKINT(__threadUsedStackSize(__intVal(i))) ); |
699 | 1170 |
} |
1171 |
%}. |
|
1172 |
^ nil |
|
1173 |
! |
|
1174 |
||
1175 |
vmTrace:aBoolean |
|
1176 |
"turn on/off VM message tracing for the receiver. |
|
1177 |
This is meant for ST/X debugging, and may vanish. |
|
1178 |
Expect lots of output, once this is turned on." |
|
1179 |
||
1180 |
%{ /* NOCONTEXT */ |
|
1181 |
OBJ i; |
|
1182 |
||
1133 | 1183 |
if (__isSmallInteger(i = __INST(id))) { |
1184 |
__threadTracing(__intVal(i), aBoolean); |
|
699 | 1185 |
} |
1186 |
%}. |
|
1187 |
! ! |
|
1188 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1189 |
!Process methodsFor:'obsolete'! |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1190 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1191 |
exitAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1192 |
"Obsoleted by addExitAction: / removeAllExitActions. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1193 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1194 |
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
|
1195 |
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
|
1196 |
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
|
1197 |
|
5870 | 1198 |
<resource:#obsolete> |
1199 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1200 |
self obsoleteMethodWarning:'use addExitAction: / removeAllExitActions'. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1201 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1202 |
aBlock isNil ifTrue:[ |
14722 | 1203 |
^ self removeAllExitActions. |
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1204 |
]. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1205 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1206 |
^ self addExitAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1207 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1208 |
"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
|
1209 |
"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
|
1210 |
! |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1211 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1212 |
suspendAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1213 |
"Obsoleted by addSuspendAction: / removeAllSuspendActions. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1214 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1215 |
Add aBlock to the processes suspend actions. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1216 |
This block will be evaluated when a process gets suspended. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1217 |
A nil argument removes all suspendActions." |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1218 |
|
5870 | 1219 |
<resource:#obsolete> |
1220 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1221 |
self obsoleteMethodWarning:'use addSuspendAction: / removeAllSuspendActions'. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1222 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1223 |
aBlock isNil ifTrue:[ |
14722 | 1224 |
^ self removeAllSuspendActions. |
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1225 |
]. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1226 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1227 |
^ self addSuspendAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1228 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1229 |
"Modified: 12.1.1997 / 00:38:22 / cg" |
9361 | 1230 |
! |
1231 |
||
1232 |
terminateAllSubprocesses |
|
1233 |
<resource:#obsolete> |
|
1234 |
self obsoleteMethodWarning:'use #terminateAllSubprocessesInGroup'. |
|
1235 |
self terminateAllSubprocessesInGroup. |
|
1236 |
! |
|
1237 |
||
1238 |
terminateWithAllSubprocesses |
|
1239 |
<resource:#obsolete> |
|
1240 |
self obsoleteMethodWarning:'use #terminateWithAllSubprocessesInGroup'. |
|
1241 |
self terminateWithAllSubprocessesInGroup. |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1242 |
! ! |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1243 |
|
699 | 1244 |
!Process methodsFor:'printing & storing'! |
1245 |
||
1246 |
printOn:aStream |
|
1247 |
"a little more info in my printed representation" |
|
1248 |
||
1249 |
aStream nextPutAll:state article; |
|
14722 | 1250 |
space; |
1251 |
nextPutAll:state; |
|
1252 |
nextPutAll:' Process ('; |
|
1253 |
nextPutAll:self nameOrId. |
|
6944
491b35cf0bf3
printString changed to include id
Claus Gittinger <cg@exept.de>
parents:
6784
diff
changeset
|
1254 |
name notNil ifTrue:[ |
14722 | 1255 |
aStream |
1256 |
nextPutAll:', id='; |
|
1257 |
nextPutAll:id printString. |
|
6944
491b35cf0bf3
printString changed to include id
Claus Gittinger <cg@exept.de>
parents:
6784
diff
changeset
|
1258 |
]. |
14722 | 1259 |
aStream |
1260 |
nextPutAll:')' |
|
159 | 1261 |
! ! |
1262 |
||
1263 |
!Process methodsFor:'private'! |
|
1264 |
||
1265 |
for:aBlock priority:aPrio |
|
1266 |
"setup the new process - the receiver is not scheduled for |
|
1267 |
execution, to get it running, send it #resume" |
|
1268 |
||
339 | 1269 |
|nm active| |
159 | 1270 |
|
1271 |
prio := aPrio. |
|
1272 |
startBlock := aBlock. |
|
339 | 1273 |
restartable := false. |
22326 | 1274 |
interruptsDisabled := false. |
159 | 1275 |
|
10436
2782fa4bd45a
#newProcess et al never return nil - but raise an exception
Stefan Vogel <sv@exept.de>
parents:
9361
diff
changeset
|
1276 |
Processor newProcessFor:self. |
159 | 1277 |
|
1278 |
" |
|
1279 |
give me a user-friendly name |
|
1280 |
" |
|
339 | 1281 |
active := Processor activeProcess. |
2268
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
1282 |
(nm := active name) notNil ifTrue:[ |
22326 | 1283 |
" |
1284 |
avoid name inflation |
|
1285 |
" |
|
1286 |
(nm endsWith:' sub') ifFalse:[ |
|
1287 |
nm := nm , ' [' , active id printString , '] sub' |
|
1288 |
]. |
|
1289 |
name := nm |
|
1529
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
1290 |
]. |
5675
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1291 |
creatorId := active id. |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1292 |
processGroupId := active processGroupId. |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1293 |
(processGroupId isNil or:[processGroupId == 0]) ifTrue:[ |
22326 | 1294 |
processGroupId := creatorId. |
5675
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1295 |
]. |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1296 |
|
4880 | 1297 |
"/ since groupId is used to detect a systemProcess (0), |
1298 |
"/ do not allow a 0 here; need an explicit beSystemProcess. |
|
1299 |
processGroupId == 0 ifTrue:[processGroupId := nil]. |
|
1529
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
1300 |
|
22326 | 1301 |
"Modified: / 25-01-1997 / 01:28:54 / cg" |
1302 |
"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
|
1303 |
! ! |
159 | 1304 |
|
7257 | 1305 |
!Process methodsFor:'private-scheduler access'! |
1 | 1306 |
|
699 | 1307 |
setId:idNumber state:stateSymbol |
1308 |
"set id and state - not for public use" |
|
375 | 1309 |
|
699 | 1310 |
id := idNumber. |
4880 | 1311 |
creatorId := 0. |
1312 |
processGroupId := nil. |
|
699 | 1313 |
state := stateSymbol. |
8787 | 1314 |
singleStepping isNil ifTrue:[ |
14722 | 1315 |
singleStepping := false |
8787 | 1316 |
]. |
1317 |
restartable isNil ifTrue:[ |
|
14722 | 1318 |
restartable := false |
8787 | 1319 |
]. |
1320 |
interruptsDisabled isNil ifTrue:[ |
|
14722 | 1321 |
interruptsDisabled := false |
8787 | 1322 |
]. |
1844 | 1323 |
|
1324 |
"Modified: 30.10.1996 / 00:35:29 / cg" |
|
182 | 1325 |
! |
1326 |
||
159 | 1327 |
setPriority:aNumber |
1328 |
"set priority without telling processor - not for public use" |
|
1329 |
||
1330 |
prio := aNumber |
|
1331 |
! |
|
1332 |
||
1333 |
setStartBlock:aBlock |
|
19452 | 1334 |
"set the receiver's startup block" |
159 | 1335 |
|
1336 |
startBlock := aBlock |
|
1337 |
! |
|
13 | 1338 |
|
159 | 1339 |
setStateTo:newState if:oldState |
1340 |
state == oldState ifTrue:[state := newState] |
|
1341 |
! |
|
1342 |
||
1343 |
setStateTo:newState if:oldState1 or:oldState2 |
|
1344 |
(state == oldState1 or:[state == oldState2]) ifTrue:[state := newState] |
|
699 | 1345 |
! ! |
1346 |
||
818 | 1347 |
!Process methodsFor:'queries'! |
1348 |
||
5397 | 1349 |
isActive |
1350 |
"return true if I am the active process" |
|
1351 |
||
1352 |
^ Processor activeProcess == self |
|
1353 |
! |
|
1354 |
||
818 | 1355 |
isDead |
10553 | 1356 |
"return true, if the receiver is a dead process" |
818 | 1357 |
|
10553 | 1358 |
^ (id isNil or:[state isNil or:[state == #dead]]) |
818 | 1359 |
|
1360 |
"Modified: 23.12.1995 / 18:35:29 / cg" |
|
1361 |
! |
|
1362 |
||
14359 | 1363 |
isDebugged |
1364 |
"return true, iff the receiver process is currently being debugged |
|
1365 |
(i.e. is stopped and a debugger sits on top of it)" |
|
1366 |
||
1367 |
^ (state == #debug) |
|
1368 |
||
1369 |
"Created: / 26-09-2012 / 14:56:36 / cg" |
|
1370 |
! |
|
1371 |
||
22526 | 1372 |
isDebuggerProcess |
1373 |
"return true, iff the receiver process is currently running a Debugger or |
|
1374 |
an Inspector. Senders may behave differently and e.g. timeout on |
|
1375 |
endless blocking operations." |
|
1376 |
||
1377 |
^ self environmentAt:#isDebuggerProcess ifAbsent:false. |
|
1378 |
||
1379 |
"Created: / 01-02-2018 / 10:15:49 / stefan" |
|
1380 |
! |
|
1381 |
||
4874
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1382 |
isGUIProcess |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1383 |
"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
|
1384 |
I.e. a windowGroup process. |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1385 |
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
|
1386 |
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
|
1387 |
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
|
1388 |
|
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1389 |
^ processType == #gui |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1390 |
! |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1391 |
|
818 | 1392 |
isRestartable |
1393 |
"return true, iff the receiver is restartable" |
|
1394 |
||
1395 |
^ restartable |
|
1396 |
! |
|
1397 |
||
1398 |
isSingleStepping |
|
1399 |
^ singleStepping |
|
1400 |
! |
|
1401 |
||
5643 | 1402 |
isStopped |
1403 |
"return true, iff the receiver is stopped" |
|
1404 |
||
1405 |
^ (state == #stopped) |
|
1406 |
||
1407 |
"Modified: 23.12.1995 / 18:35:29 / cg" |
|
1408 |
! |
|
1409 |
||
2636
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1410 |
isSystemProcess |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1411 |
"return true if aProcess is a system process, |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1412 |
which should not be suspended/terminated etc.." |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1413 |
|
14722 | 1414 |
^ (Processor isPureEventDriven |
2636
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1415 |
or:[id == 0 |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1416 |
or:[processGroupId == 0 |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1417 |
or:[(Display notNil and:[Display dispatchProcess == self]) |
14722 | 1418 |
]]]) |
2636
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1419 |
|
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1420 |
" |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1421 |
Processor activeProcessIsSystemProcess |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1422 |
" |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1423 |
|
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1424 |
"Created: 17.4.1997 / 12:57:37 / stefan" |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1425 |
! |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1426 |
|
17407 | 1427 |
isUserProcess |
1428 |
"return true if aProcess is a user process." |
|
1429 |
||
1430 |
^ processGroupId ~~ 0 and:[id ~~ 0] |
|
1431 |
! |
|
1432 |
||
818 | 1433 |
nameOrId |
1434 |
"return a string to identify the process - either name or id" |
|
1435 |
||
1436 |
name notNil ifTrue:[^ name]. |
|
1437 |
^ id printString |
|
5675
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1438 |
! |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1439 |
|
9361 | 1440 |
parentProcess |
17244 | 1441 |
"answer my parent. |
1442 |
Notice: we do only keep the id here, to prevent the parentProcess from being |
|
1443 |
referenced (and therefore not garbage collected if it terminates)" |
|
9361 | 1444 |
|
14722 | 1445 |
ProcessorScheduler knownProcessesDo:[:p| |
17544 | 1446 |
p id = creatorId ifTrue:[^ p]. |
14443 | 1447 |
]. |
1448 |
^ nil. |
|
9361 | 1449 |
|
1450 |
" |
|
1451 |
Processor activeProcess parentProcess |
|
1452 |
" |
|
14443 | 1453 |
|
1454 |
"Modified: / 26-10-2012 / 13:15:55 / cg" |
|
9361 | 1455 |
! |
1456 |
||
5675
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1457 |
processGroupLeader |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1458 |
"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
|
1459 |
|
5681 | 1460 |
|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
|
1461 |
|
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1462 |
processes := ProcessorScheduler knownProcesses. |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1463 |
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
|
1464 |
leader isNil ifTrue:[ |
14722 | 1465 |
leader := self. |
1466 |
[ |
|
1467 |
creatorId := leader creatorId. |
|
1468 |
next := processes detect:[:p| p id = creatorId |
|
1469 |
and:[p processGroupId = processGroupId]] |
|
1470 |
ifNone:nil. |
|
1471 |
] 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
|
1472 |
]. |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1473 |
|
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1474 |
^ leader. |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1475 |
|
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1476 |
" |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1477 |
Processor activeProcess processGroupLeader |
5812
e23a3fdc75cb
already-dead is a proceedable error
Claus Gittinger <cg@exept.de>
parents:
5683
diff
changeset
|
1478 |
" |
e23a3fdc75cb
already-dead is a proceedable error
Claus Gittinger <cg@exept.de>
parents:
5683
diff
changeset
|
1479 |
! ! |
818 | 1480 |
|
699 | 1481 |
!Process methodsFor:'special'! |
1482 |
||
15964 | 1483 |
externalLookupPopIfEqual: lookupObject |
1484 |
"Called by method lookup MOP when an lookup context is to be unwound |
|
1485 |
to cleanup lookup stack" |
|
1486 |
lookupActivations first == lookupObject ifTrue:[ |
|
16562 | 1487 |
lookupActivations := lookupActivations second. |
15964 | 1488 |
]. |
1489 |
||
1490 |
"Created: / 04-10-2013 / 10:46:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1491 |
"Modified (comment): / 04-10-2013 / 12:08:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1492 |
! |
|
1493 |
||
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1494 |
millisecondDelay:millis |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1495 |
"suspend the current process for some time. |
16846 | 1496 |
Attention: |
17544 | 1497 |
If the receiver is a system process (i.e. scheduler or event dispatcher) |
1498 |
this blocks the whole Smalltalk for the time delta; |
|
1499 |
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
|
1500 |
|
2636
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1501 |
(self isSystemProcess) ifTrue:[ |
17544 | 1502 |
OperatingSystem millisecondDelay:millis |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1503 |
] ifFalse:[ |
17544 | 1504 |
Delay waitForMilliseconds:millis |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1505 |
] |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1506 |
|
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1507 |
"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
|
1508 |
"Modified: 17.4.1997 / 13:02:25 / stefan" |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1509 |
! |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1510 |
|
699 | 1511 |
trapRestrictedMethods:trap |
1512 |
"Allow/deny the execution of restricted methods. |
|
1513 |
Process specific method restriction is not implemented yet, so this call is |
|
1514 |
redirected to ObjectMemory and causes a system wide restriction. |
|
1515 |
||
1516 |
Notice: method restriction is a nonstandard feature, not supported |
|
1517 |
by other smalltalk implementations and not specified in the ANSI spec. |
|
1518 |
This is EXPERIMENTAL - and being evaluated for usability. |
|
1519 |
It may change or even vanish (if it shows to be not useful)." |
|
1520 |
||
1521 |
^ObjectMemory trapRestrictedMethods:trap |
|
1522 |
||
1523 |
" |
|
1524 |
Processor activeProcess trapRestrictedMethods:true |
|
1525 |
Processor activeProcess trapRestrictedMethods:false |
|
1526 |
" |
|
1527 |
||
1528 |
"Created: 8.11.1995 / 19:45:04 / stefan" |
|
1529 |
! |
|
1530 |
||
1531 |
uninterruptablyDo:aBlock |
|
14722 | 1532 |
"execute aBlock with interrupts blocked. |
699 | 1533 |
This does not prevent preemption by a higher priority processes |
1534 |
if any becomes runnable due to the evaluation of aBlock |
|
1535 |
(i.e. if a semaphore is signalled there)." |
|
1536 |
||
1537 |
"we must keep track of blocking-state if this is called nested" |
|
2302 | 1538 |
(OperatingSystem blockInterrupts) ifTrue:[ |
14722 | 1539 |
"/ already blocked |
1540 |
^ aBlock value |
|
2302 | 1541 |
]. |
699 | 1542 |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6322
diff
changeset
|
1543 |
^ aBlock ensure:[OperatingSystem unblockInterrupts] |
159 | 1544 |
! |
1545 |
||
699 | 1546 |
waitUntilSuspended |
1547 |
"wait until the receiver is suspended." |
|
1548 |
||
5377 | 1549 |
self isDead ifFalse:[ |
22175 | 1550 |
[ |
1551 |
"/ must check again - interrupt could have happened |
|
1552 |
"/ and process already terminated. |
|
1553 |
self isDead ifFalse:[ |
|
1554 |
suspendSemaphore isNil ifTrue:[ |
|
1555 |
suspendSemaphore := Semaphore name:'process suspend' |
|
1556 |
]. |
|
1557 |
suspendSemaphore wait |
|
1558 |
] |
|
1559 |
] valueUninterruptably |
|
5377 | 1560 |
] |
699 | 1561 |
|
22175 | 1562 |
"Modified: / 09-08-2017 / 11:55:51 / cg" |
699 | 1563 |
! |
1564 |
||
1565 |
waitUntilTerminated |
|
1566 |
"wait until the receiver is terminated. |
|
1567 |
This method allows another process to wait till the receiver finishes." |
|
1568 |
||
6774
6711472e6df4
oops - waitUntil terminated for a process that did not rune
penk
parents:
6739
diff
changeset
|
1569 |
self waitUntilTerminatedWithTimeout:nil |
1033 | 1570 |
|
1789 | 1571 |
" |
1572 |
|p| |
|
1573 |
||
6774
6711472e6df4
oops - waitUntil terminated for a process that did not rune
penk
parents:
6739
diff
changeset
|
1574 |
p := [100 timesRepeat:[1000 factorial]] forkAt:4. |
1789 | 1575 |
|
1576 |
Transcript showCR:'now waiting ...'. |
|
1577 |
p waitUntilTerminated. |
|
1578 |
Transcript showCR:'done.' |
|
1579 |
" |
|
1580 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1581 |
"Modified: 12.1.1997 / 00:40:59 / cg" |
699 | 1582 |
! |
1583 |
||
4735
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1584 |
waitUntilTerminatedWithTimeout:secondsOrNil |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1585 |
"wait until the receiver is terminated or (if non-nil) until |
14722 | 1586 |
the time period exired. |
13206
bffd4afb5be0
comment/format in: #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
13016
diff
changeset
|
1587 |
Returns true if a timeout occurred. |
8566 | 1588 |
This method allows another process to wait until the receiver finishes |
4735
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1589 |
(optionally) within some time." |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1590 |
|
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1591 |
|sema didTimeout| |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1592 |
|
10553 | 1593 |
didTimeout := false. |
1594 |
||
5377 | 1595 |
self isDead ifFalse:[ |
22175 | 1596 |
[ |
1597 |
"/ must check again - interrupt could have happened |
|
1598 |
"/ and process already terminated. |
|
1599 |
self isDead ifFalse:[ |
|
1600 |
sema := Semaphore name:'process termination'. |
|
1601 |
self addExitAction:[sema signal]. |
|
1602 |
didTimeout := (sema waitWithTimeout:secondsOrNil) isNil |
|
1603 |
] |
|
1604 |
] valueUninterruptably. |
|
5377 | 1605 |
]. |
10553 | 1606 |
^ didTimeout |
4735
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1607 |
|
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1608 |
" |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1609 |
|p| |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1610 |
|
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1611 |
p := [10 timesRepeat:[10000 factorial]] forkAt:4. |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1612 |
|
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1613 |
Transcript showCR:'now waiting ...'. |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1614 |
(p waitUntilTerminatedWithTimeout:2) ifTrue:[ |
22175 | 1615 |
Transcript showCR:'timeout occurred.' |
4735
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1616 |
] |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1617 |
" |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1618 |
|
22175 | 1619 |
"Modified: / 09-08-2017 / 11:55:56 / cg" |
4735
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1620 |
! |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1621 |
|
9059 | 1622 |
withHigherPriorityDo:aBlock |
1623 |
"execute aBlock at a higher priority." |
|
1624 |
||
1625 |
^ self withPriority:(prio + 1) do:aBlock |
|
1626 |
||
1627 |
" |
|
1628 |
Processor activeProcess withHigherPriorityDo:[3000 factorial] |
|
1629 |
" |
|
1630 |
! |
|
1631 |
||
699 | 1632 |
withLowerPriorityDo:aBlock |
1633 |
"execute aBlock at a lower priority. This can be used to perform |
|
1634 |
time-consuming operations at a more user-friendly priority." |
|
159 | 1635 |
|
699 | 1636 |
^ self withPriority:(prio - 1) do:aBlock |
1637 |
||
1638 |
" |
|
1639 |
Processor activeProcess withLowerPriorityDo:[3000 factorial] |
|
1640 |
" |
|
1641 |
! |
|
1642 |
||
1643 |
withPriority:aPrio do:aBlock |
|
1644 |
"execute aBlock at another priority. This can be used to perform |
|
1645 |
time-consuming operations at a more user-friendly priority, |
|
1646 |
or some critical action at a higher priority. Do not use too high |
|
1647 |
of a priority to avoid locking up the system (event processing takes place |
|
1648 |
at 24)" |
|
1649 |
||
1650 |
|oldprio| |
|
1651 |
||
1652 |
oldprio := prio. |
|
1653 |
self priority:aPrio. |
|
1654 |
||
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6322
diff
changeset
|
1655 |
^ aBlock ensure:[ |
14722 | 1656 |
self priority:oldprio |
699 | 1657 |
] |
1658 |
||
1659 |
" |
|
1660 |
Processor activeProcess withPriority:7 do:[3000 factorial] |
|
1661 |
" |
|
1662 |
"be careful - even ^C wont work until done: |
|
1663 |
Processor activeProcess withPriority:25 do:[3000 factorial] |
|
1664 |
" |
|
2839
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1665 |
! |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1666 |
|
4433 | 1667 |
withPriority:lowPrio to:highPrio do:aBlock |
1668 |
"execute aBlock at a priority range. This can be used to perform |
|
1669 |
time-consuming operations at a more user-friendly priority, |
|
1670 |
or some critical action at a higher priority. Do not use too high |
|
1671 |
of a priority to avoid locking up the system (event processing takes place |
|
1672 |
at 24)" |
|
1673 |
||
1674 |
|oldprio oldRange| |
|
1675 |
||
1676 |
oldprio := prio. |
|
1677 |
oldRange := priorityRange. |
|
1678 |
self priorityRange:(lowPrio to:highPrio). |
|
1679 |
||
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6322
diff
changeset
|
1680 |
^ aBlock ensure:[ |
14722 | 1681 |
self priorityRange:oldRange. |
1682 |
self priority:oldprio. |
|
4433 | 1683 |
] |
1684 |
||
1685 |
" |
|
1686 |
Processor activeProcess withPriority:7 to:8 do:[3000 factorial] |
|
1687 |
" |
|
1688 |
! |
|
1689 |
||
2839
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1690 |
withSystemBackgroundPriorityDo:aBlock |
14722 | 1691 |
"execute aBlock at system background priority. |
2839
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1692 |
This can be used to perform |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1693 |
background operations at a more user-friendly priority." |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1694 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1695 |
^ self withPriority:(Processor systemBackgroundPriority) do:aBlock |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1696 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1697 |
" |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1698 |
Processor activeProcess withSystemBackgroundPriorityDo:[3000 factorial] |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1699 |
" |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1700 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1701 |
"Created: 7.8.1997 / 12:56:23 / cg" |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1702 |
! |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1703 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1704 |
withUserBackgroundPriorityDo:aBlock |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1705 |
"execute aBlock at background priority. This can be used to perform |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1706 |
time-consuming operations at a more user-friendly priority." |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1707 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1708 |
^ self withPriority:(Processor userBackgroundPriority) do:aBlock |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1709 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1710 |
" |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1711 |
Processor activeProcess withUserBackgroundPriorityDo:[3000 factorial] |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1712 |
" |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1713 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1714 |
"Created: 6.8.1997 / 15:40:02 / cg" |
202 | 1715 |
! ! |
1716 |
||
5256 | 1717 |
!Process methodsFor:'startup'! |
116 | 1718 |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1719 |
imageRestart |
699 | 1720 |
"restart the process from the beginning. |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1721 |
This is sent by the ProcessorScheduler at image restart time, |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1722 |
to all restartable processes." |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1723 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1724 |
|savedGroupId| |
699 | 1725 |
|
1726 |
"/ ('restart process ' , id printString) errorPrintNL. |
|
1727 |
||
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1728 |
savedGroupId := processGroupId. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1729 |
|
14722 | 1730 |
(Processor newProcessFor:self withId:id) ifFalse:[ |
5450 | 1731 |
"for some reason, the Processor was unable to create |
1732 |
a VM process for me ...." |
|
699 | 1733 |
|
5450 | 1734 |
('Process [warning]: process ' , id printString , ' failed to restart.') errorPrintCR. |
1735 |
^ nil |
|
699 | 1736 |
]. |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1737 |
processGroupId := savedGroupId. |
699 | 1738 |
self resume |
1086 | 1739 |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1740 |
"Created: 28.10.1996 / 20:32:34 / cg" |
2130
b9e7e1cf98bd
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1741 |
"Modified: 10.1.1997 / 18:01:13 / cg" |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1742 |
! |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1743 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1744 |
restart |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1745 |
"restart the process from the beginning. |
21433 | 1746 |
This is only possible, if it's restartable." |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1747 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1748 |
restartable ifFalse:[ |
23016 | 1749 |
^ self proceedableError:'process is not restartable' |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1750 |
]. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1751 |
|
22693 | 1752 |
self interruptWith:[RestartProcessRequest raise] |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1753 |
|
21433 | 1754 |
"Modified: / 12-01-1997 / 00:54:32 / cg" |
1755 |
"Modified (comment): / 13-02-2017 / 20:29:07 / cg" |
|
22693 | 1756 |
"Modified: / 23-04-2018 / 14:01:40 / stefan" |
23016 | 1757 |
"Modified: / 24-05-2018 / 21:03:56 / Claus Gittinger" |
699 | 1758 |
! |
1759 |
||
116 | 1760 |
start |
159 | 1761 |
"start the process - this is sent by the VM to the process to get |
1762 |
the process up and running. |
|
329 | 1763 |
Sending #start to the process (instead of directly executing the startBlock) |
14722 | 1764 |
allows more flexible handling of processes, since anything that responds |
329 | 1765 |
to #start can be handled transparently by the VM then ..." |
159 | 1766 |
|
1767 |
|block| |
|
116 | 1768 |
|
21333 | 1769 |
startBlock isNil ifTrue:[ |
1770 |
"is this artificial restriction useful ?" |
|
23016 | 1771 |
self proceedableError:'a process cannot be started twice'. |
21333 | 1772 |
^ self. |
1773 |
]. |
|
1774 |
||
1775 |
"/ |
|
1776 |
"/ just for your convenience ... |
|
1777 |
"/ |
|
1778 |
startTimestamp := Timestamp now. |
|
1779 |
name isNil ifTrue:[ |
|
1780 |
name := '(' , startBlock displayString , ')' |
|
1781 |
]. |
|
1782 |
||
1783 |
"save block for possible restart" |
|
1784 |
block := startBlock. |
|
1785 |
restartable ~~ true ifTrue:[ |
|
1786 |
startBlock := nil |
|
1787 |
]. |
|
1788 |
||
1789 |
[ |
|
21324 | 1790 |
"/ |
21333 | 1791 |
"/ block is the one which received the fork/newProcess some time ago... |
1792 |
"/ |
|
1793 |
self exceptionHandlerSet handleDo:block |
|
1794 |
] on:CaughtSignals do:[:ex | |
|
1795 |
"/ |
|
1796 |
"/ CaughtSignals: handle Process-Termination, Process-Restart and Abort |
|
1797 |
"/ |
|
1798 |
ex creator == RestartProcessRequest ifTrue:[ |
|
1799 |
ex restart |
|
21324 | 1800 |
]. |
21333 | 1801 |
ex return |
1802 |
] ensure:[ |
|
1803 |
self terminateNoSignal |
|
1804 |
]. |
|
1805 |
||
1806 |
"Modified: / 17-11-2001 / 16:45:32 / cg" |
|
1807 |
"Modified: / 31-01-2017 / 16:41:05 / stefan" |
|
23016 | 1808 |
"Modified: / 24-05-2018 / 21:04:12 / Claus Gittinger" |
1 | 1809 |
! ! |
1810 |
||
7263 | 1811 |
!Process methodsFor:'suspend & resume'! |
1 | 1812 |
|
5592 | 1813 |
abort |
14722 | 1814 |
"raise an AbortOperationRequest in the receiver process. |
1815 |
Most processes willing to handle this will return to some save state |
|
5592 | 1816 |
(typically, some kind of event loop). |
1817 |
If not handled, this will result in termination of the process." |
|
1818 |
||
1819 |
Processor activeProcess == self ifTrue:[ |
|
14722 | 1820 |
AbortOperationRequest raiseRequest |
5592 | 1821 |
] ifFalse:[ |
14722 | 1822 |
self interruptWith:[ |
1823 |
AbortOperationRequest raiseRequest |
|
1824 |
]. |
|
5592 | 1825 |
] |
6204
2bafef9151dd
class based exceptions - abortSignal;
Claus Gittinger <cg@exept.de>
parents:
5870
diff
changeset
|
1826 |
|
2bafef9151dd
class based exceptions - abortSignal;
Claus Gittinger <cg@exept.de>
parents:
5870
diff
changeset
|
1827 |
"Modified: / 16.11.2001 / 17:39:18 / cg" |
5592 | 1828 |
! |
1829 |
||
699 | 1830 |
resume |
1831 |
"resume the receiver process" |
|
1832 |
||
4002
341a896cb334
allow stopping a waiting process
Claus Gittinger <cg@exept.de>
parents:
3785
diff
changeset
|
1833 |
state == #stopped ifTrue:[ |
5450 | 1834 |
state := #run. |
4002
341a896cb334
allow stopping a waiting process
Claus Gittinger <cg@exept.de>
parents:
3785
diff
changeset
|
1835 |
]. |
699 | 1836 |
Processor resume:self |
1837 |
! |
|
1838 |
||
1839 |
resumeForSingleSend |
|
1840 |
"resume the receiver process, but only let it execute a single send." |
|
1841 |
||
1842 |
Processor resumeForSingleSend:self |
|
1843 |
! |
|
1844 |
||
326 | 1845 |
stop |
1846 |
"suspend the receiver process - will continue to run when a resume is sent. |
|
1847 |
A stopped process will not be resumed for interrupt processing." |
|
1848 |
||
11283 | 1849 |
self suspendWithState:#stopped. |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1850 |
|
3679 | 1851 |
"Modified: / 13.12.1995 / 13:22:58 / stefan" |
1852 |
"Modified: / 27.7.1998 / 23:37:15 / cg" |
|
326 | 1853 |
! |
1854 |
||
1 | 1855 |
suspend |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1856 |
"suspend the receiver process - it will continue to run when a resume is sent. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1857 |
Notice, that an interrupt will also resume the receiver, |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1858 |
so any waiting code should be prepared for premature return from |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1859 |
a suspend (see wait code in Semaphore). |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1860 |
Use #stop for a hard-suspend, which is not affected by interrupts." |
13 | 1861 |
|
1474 | 1862 |
self suspendWithState:#suspended |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1863 |
|
1474 | 1864 |
"Modified: 17.6.1996 / 14:41:34 / cg" |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1865 |
! |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1866 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1867 |
suspendWithState:aStateSymbol |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1868 |
"like suspend, this suspends the receiver process until a resume is sent. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1869 |
This sets the state to the argument, aStateSymbol, which is shown |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1870 |
in the ProcessMonitor (instead of #suspended). |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1871 |
(i.e. no new functionality, but a bit more debuggability) |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1872 |
Notice, that an interrupt will also resume the receiver, |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1873 |
so any waiting code should be prepared for premature return from |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1874 |
a suspend (see wait code in Semaphore). |
16312 | 1875 |
Use #stop for a hard-suspend, which is not affected by interrupts. |
1876 |
Should be called with interrupts disabled." |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1877 |
|
23038 | 1878 |
<resource: #skipInDebuggersWalkBack> |
1879 |
||
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1880 |
suspendSemaphore notNil ifTrue:[suspendSemaphore signalForAll]. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1881 |
suspendActions notNil ifTrue:[ |
23038 | 1882 |
|savedState| |
1883 |
||
1884 |
savedState := state. |
|
1885 |
state := #aboutToSuspend. |
|
1886 |
suspendActions do:[:action | action value]. |
|
1887 |
state ~~ #aboutToSuspend ifTrue:[ |
|
1888 |
"/ mhmh - one of the suspendActions lead to making me active again; |
|
1889 |
"/ bail out. |
|
1890 |
"/ This fixes the Semaphore was signalled, but process did not run error, |
|
1891 |
"/ which can happen when a process with a suspend action goes into a readWait, |
|
1892 |
"/ and the suspend action does a thread switch, and the readWait semaphore gets |
|
1893 |
"/ signalled before we come back here. Then the semaphore wakeup will have already |
|
1894 |
"/ place me back into the run state, so I should not go into a suspend below. |
|
1895 |
^ self. |
|
1896 |
]. |
|
1897 |
state := savedState. |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1898 |
]. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1899 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1900 |
" |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1901 |
this is a bit of a kludge: allow someone else to |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1902 |
set the state to something like #ioWait etc. |
19452 | 1903 |
In this case, do not set the receiver's state to #suspend. |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1904 |
(All of this to enhance the output of the process monitor ...) |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1905 |
" |
14722 | 1906 |
(state == #active |
1907 |
or:[state == #run |
|
4002
341a896cb334
allow stopping a waiting process
Claus Gittinger <cg@exept.de>
parents:
3785
diff
changeset
|
1908 |
or:[aStateSymbol == #stopped]]) ifTrue:[ |
23038 | 1909 |
state := aStateSymbol. |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1910 |
]. |
1 | 1911 |
Processor suspend:self |
23038 | 1912 |
|
1913 |
"Modified: / 30-05-2018 / 13:57:00 / Claus Gittinger" |
|
1 | 1914 |
! |
1915 |
||
1916 |
terminate |
|
14722 | 1917 |
"terminate the receiver process. |
1918 |
Termination is done by raising the terminateSignal in the receiver process, |
|
2689 | 1919 |
which can be caught. |
22693 | 1920 |
If the process is stopped, it will be resumed so that it can die. |
375 | 1921 |
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
|
1922 |
will be performed before the process is really terminated. |
dff1649c072c
resume the process when terminated.
Claus Gittinger <cg@exept.de>
parents:
4002
diff
changeset
|
1923 |
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
|
1924 |
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
|
1925 |
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
|
1926 |
done." |
10 | 1927 |
|
22693 | 1928 |
self terminateWithException:TerminateProcessRequest newException. |
21313 | 1929 |
|
1930 |
"Modified: / 24-08-1998 / 18:29:46 / cg" |
|
22693 | 1931 |
"Modified: / 23-04-2018 / 14:31:06 / stefan" |
1932 |
"Modified (comment): / 23-04-2018 / 15:40:43 / stefan" |
|
159 | 1933 |
! |
1934 |
||
4875 | 1935 |
terminateAllGUISubprocesses |
19452 | 1936 |
"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
|
1937 |
(i.e. all processes which are offsprings of the receiver, except for |
4875 | 1938 |
the receiver itself)." |
1939 |
||
5377 | 1940 |
id isNil ifTrue:[ |
20808 | 1941 |
"/ problem: |
1942 |
"/ if receiver is already dead, its id is nil. |
|
1943 |
"/ children are found by looking for processes with a parentID identical to |
|
1944 |
"/ mine - ifNil, system processes are found, which is probably not what you |
|
1945 |
"/ want ... |
|
1946 |
"/ FIX: remember the id (or don't nil it when terminating) |
|
1947 |
"/ requires VM changes. |
|
1948 |
ProcessorScheduler invalidProcessSignal |
|
1949 |
raiseRequestWith:self |
|
1950 |
errorString:'process is already dead - cannot determine child processes'. |
|
1951 |
^ self |
|
5377 | 1952 |
]. |
4875 | 1953 |
ProcessorScheduler knownProcesses do:[:aProcess | |
21313 | 1954 |
(aProcess ~~ self and:[aProcess creatorId == id and:[aProcess isGUIProcess]]) ifTrue:[ |
1955 |
aProcess terminateWithAllGUISubprocesses |
|
1956 |
]. |
|
4875 | 1957 |
]. |
1958 |
||
14443 | 1959 |
"Created: / 28-10-1996 / 20:43:32 / cg" |
1960 |
"Modified: / 26-10-2012 / 13:16:35 / cg" |
|
21313 | 1961 |
"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
|
1962 |
! |
4875 | 1963 |
|
6783 | 1964 |
terminateAllSubprocessesInGroup |
1965 |
"terminate all subprocesses which have the receiver process as groupID, |
|
1966 |
and their group-children as well. |
|
19452 | 1967 |
(i.e. all processes in the receiver's process group, except for the receiver itself, |
6783 | 1968 |
and recursively oll of their group processes.)." |
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
1969 |
|
5377 | 1970 |
id isNil ifTrue:[ |
20808 | 1971 |
"/ problem: |
1972 |
"/ if receiver is already dead, its id is nil. |
|
1973 |
"/ children are found by looking for processes with a parentID identical to |
|
1974 |
"/ mine - ifNil, system processes are found, which is probably not what you |
|
1975 |
"/ want ... |
|
1976 |
"/ FIX: remember the id (or don't nil it when terminating) |
|
1977 |
"/ requires VM changes. |
|
1978 |
ProcessorScheduler invalidProcessSignal |
|
1979 |
raiseRequestWith:self |
|
1980 |
errorString:'process is already dead - cannot determine child processes'. |
|
1981 |
^ self |
|
5377 | 1982 |
]. |
9300 | 1983 |
self terminateAllSubprocessesInGroup:id |
1984 |
! |
|
1985 |
||
1986 |
terminateAllSubprocessesInGroup:aGroup |
|
1987 |
"terminate all subprocesses which have aGroup as groupID, |
|
1988 |
and their group-children as well. |
|
19452 | 1989 |
(i.e. all processes in the receiver's process group, except for the receiver itself, |
9300 | 1990 |
and recursively oll of their group processes.)." |
1991 |
||
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
1992 |
ProcessorScheduler knownProcesses do:[:aProcess | |
21313 | 1993 |
(aProcess ~~ self and:[aProcess processGroupId == aGroup]) ifTrue:[ |
1994 |
aProcess terminateWithAllSubprocessesInGroup |
|
1995 |
]. |
|
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
1996 |
]. |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1997 |
|
21313 | 1998 |
"Created: / 28-10-1996 / 20:43:32 / cg" |
1999 |
"Modified: / 03-11-1997 / 00:28:06 / cg" |
|
2000 |
"Modified: / 24-01-2017 / 17:42:33 / stefan" |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2001 |
! |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2002 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2003 |
terminateGroup |
14722 | 2004 |
"terminate the receiver with all of its created subprocesses |
19452 | 2005 |
that are in the receiver's process group." |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2006 |
|
5683
3312d4d798dc
terminateAllGUISubprocesses no longer restricted to processGroup.
Stefan Vogel <sv@exept.de>
parents:
5681
diff
changeset
|
2007 |
id isNil ifTrue:[ |
20808 | 2008 |
"/ problem: |
2009 |
"/ if receiver is already dead, its id is nil. |
|
2010 |
"/ children are found by looking for processes with a parentID identical to |
|
2011 |
"/ mine - ifNil, system processes are found, which is probably not what you |
|
2012 |
"/ want ... |
|
2013 |
"/ FIX: remember the id (or don't nil it when terminating) |
|
2014 |
"/ requires VM changes. |
|
2015 |
ProcessorScheduler invalidProcessSignal |
|
2016 |
raiseRequestWith:self |
|
2017 |
errorString:'process is already dead - cannot determine child processes'. |
|
2018 |
^ self |
|
5683
3312d4d798dc
terminateAllGUISubprocesses no longer restricted to processGroup.
Stefan Vogel <sv@exept.de>
parents:
5681
diff
changeset
|
2019 |
]. |
3312d4d798dc
terminateAllGUISubprocesses no longer restricted to processGroup.
Stefan Vogel <sv@exept.de>
parents:
5681
diff
changeset
|
2020 |
ProcessorScheduler knownProcesses do:[:aProcess | |
21313 | 2021 |
(aProcess ~~ self and:[aProcess processGroupId == id]) ifTrue:[ |
2022 |
aProcess terminate |
|
2023 |
]. |
|
5683
3312d4d798dc
terminateAllGUISubprocesses no longer restricted to processGroup.
Stefan Vogel <sv@exept.de>
parents:
5681
diff
changeset
|
2024 |
]. |
5812
e23a3fdc75cb
already-dead is a proceedable error
Claus Gittinger <cg@exept.de>
parents:
5683
diff
changeset
|
2025 |
self terminate |
21313 | 2026 |
|
2027 |
"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
|
2028 |
! |
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
2029 |
|
159 | 2030 |
terminateNoSignal |
2197 | 2031 |
"hard-terminate the receiver process without sending a terminateSignal |
375 | 2032 |
or performing any unwind-handling. |
2197 | 2033 |
However, exit-actions are performed. |
2034 |
This is useful in case of emergency, when a buggy terminationHandler |
|
2035 |
prevents you from getting a process to terminate." |
|
375 | 2036 |
|
2037 |
|block| |
|
159 | 2038 |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
2039 |
"/ this is treated like the final suspend |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
2040 |
suspendActions notNil ifTrue:[ |
5450 | 2041 |
[suspendActions isEmpty] whileFalse:[ |
2042 |
block := suspendActions removeFirst. |
|
2043 |
block value. |
|
2044 |
] |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
2045 |
]. |
375 | 2046 |
exitActions notNil ifTrue:[ |
5450 | 2047 |
[exitActions isEmpty] whileFalse:[ |
2048 |
block := exitActions removeFirst. |
|
2049 |
block value. |
|
2050 |
] |
|
375 | 2051 |
]. |
329 | 2052 |
suspendSemaphore notNil ifTrue:[suspendSemaphore signalForAll]. |
159 | 2053 |
Processor terminateNoSignal:self |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
2054 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
2055 |
"Modified: 13.12.1995 / 13:40:14 / stefan" |
2384 | 2056 |
"Modified: 12.2.1997 / 12:41:38 / cg" |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2057 |
! |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2058 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2059 |
terminateSubprocesses |
19751 | 2060 |
"terminate all the receiver's subprocesses |
19452 | 2061 |
(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
|
2062 |
the receiver itself)." |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2063 |
|
5377 | 2064 |
id isNil ifTrue:[ |
20808 | 2065 |
"/ problem: |
2066 |
"/ if receiver is already dead, its id is nil. |
|
2067 |
"/ children are found by looking for processes with a parentID identical to |
|
2068 |
"/ mine - ifNil, system processes are found, which is probably not what you |
|
2069 |
"/ want ... |
|
2070 |
"/ FIX: remember the id (or don't nil it when terminating) |
|
2071 |
"/ requires VM changes. |
|
2072 |
ProcessorScheduler invalidProcessSignal |
|
2073 |
raiseRequestWith:self |
|
2074 |
errorString:'process is already dead - cannot determine child processes'. |
|
2075 |
^ self |
|
10496
1198c42b85f5
Be conservative when setting helper processes of executeCommand:...
Stefan Vogel <sv@exept.de>
parents:
10436
diff
changeset
|
2076 |
]. |
1198c42b85f5
Be conservative when setting helper processes of executeCommand:...
Stefan Vogel <sv@exept.de>
parents:
10436
diff
changeset
|
2077 |
processGroupId == 0 ifTrue:[ |
20808 | 2078 |
ProcessorScheduler invalidProcessSignal |
2079 |
raiseWith:self errorString:'trying to terminate the system process group'. |
|
5377 | 2080 |
]. |
21313 | 2081 |
ProcessorScheduler knownProcesses do:[:eachProcess | |
2082 |
eachProcess ~~ self ifTrue:[ |
|
2083 |
|eachProcessGroupId| |
|
2084 |
||
2085 |
eachProcessGroupId := eachProcess processGroupId. |
|
2086 |
(eachProcessGroupId == processGroupId or:[eachProcessGroupId == id]) ifTrue:[ |
|
2087 |
eachProcess terminate |
|
2088 |
]. |
|
2089 |
]. |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2090 |
]. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2091 |
|
21313 | 2092 |
"Created: / 28-10-1996 / 20:41:49 / cg" |
2093 |
"Modified: / 26-08-1997 / 03:09:57 / cg" |
|
2094 |
"Modified: / 24-01-2017 / 17:35:25 / stefan" |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2095 |
! |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2096 |
|
4875 | 2097 |
terminateWithAllGUISubprocesses |
6783 | 2098 |
"terminate the receiver with all of its created gui subprocesses and their gui children." |
4875 | 2099 |
|
2100 |
self terminateAllGUISubprocesses. |
|
2101 |
self terminate |
|
2102 |
||
2103 |
"Modified: 28.10.1996 / 20:42:00 / cg" |
|
2104 |
"Created: 28.10.1996 / 20:44:07 / cg" |
|
2105 |
! |
|
2106 |
||
6783 | 2107 |
terminateWithAllSubprocessesInGroup |
2108 |
"terminate the receiver with |
|
19452 | 2109 |
all subprocesses which have the receiver's process ID as groupID, |
6783 | 2110 |
and their group-children as well. |
19751 | 2111 |
(i.e. the receiver plus all processes in the receiver's process group, |
6783 | 2112 |
and recursively all of their group processes)." |
2113 |
||
2114 |
self terminateAllSubprocessesInGroup. |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2115 |
self terminate |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2116 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2117 |
"Modified: 28.10.1996 / 20:42:00 / cg" |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2118 |
"Created: 28.10.1996 / 20:44:07 / cg" |
22693 | 2119 |
! |
2120 |
||
2121 |
terminateWithException:aTerminateException |
|
2122 |
"terminate the receiver process. |
|
2123 |
Termination is done by raising aTerminateException in the receiver process, |
|
2124 |
which can be caught. |
|
2125 |
If the process is stopped, it will be resumed so that it can die. |
|
2126 |
All unwind actions and the exit-actions (if any) |
|
2127 |
will be performed before the process is really terminated. |
|
2128 |
Notice, that the terminate actions are performed by the receiver, |
|
2129 |
at its current priority. Therefore, in case higher prio processes are |
|
2130 |
running, it may take any arbitrary time until the termination is eventually |
|
2131 |
done." |
|
2132 |
||
2133 |
|wasBlocked| |
|
2134 |
||
2135 |
Processor activeProcess == self ifTrue:[ |
|
2136 |
"suicide: terminating myself" |
|
2137 |
NoHandlerError handle:[:ex | |
|
2138 |
"unhandled TerminateProcessRequest is not an error - |
|
2139 |
the interrupt may be delivered before a |
|
2140 |
low priority process has set up the exception handler" |
|
2141 |
ex exception ~~ aTerminateException ifTrue:[ |
|
2142 |
ex reject. |
|
2143 |
]. |
|
2144 |
] do:[ |
|
2145 |
aTerminateException raise. |
|
2146 |
]. |
|
2147 |
self terminateNoSignal. |
|
2148 |
"not reached" |
|
2149 |
^ self. |
|
2150 |
]. |
|
2151 |
||
2152 |
"the receiver is terminated from another process" |
|
2153 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2154 |
[ |
|
2155 |
(state isNil or:[state == #dead]) ifTrue:[ |
|
2156 |
^ self. |
|
2157 |
]. |
|
2158 |
state == #osWait ifTrue:[ |
|
2159 |
"osWait processes cannot be interrupted" |
|
2160 |
self terminateNoSignal. |
|
2161 |
^ self. |
|
2162 |
]. |
|
2163 |
||
2164 |
self suspendedContext isNil ifTrue:[ |
|
2165 |
"if the receiver had no chance to execute yet, |
|
2166 |
it can be shot down without a signal" |
|
2167 |
self terminateNoSignal. |
|
2168 |
^ self |
|
2169 |
] |
|
2170 |
] ensure:[ |
|
2171 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts] |
|
2172 |
]. |
|
2173 |
||
2174 |
"register an interrupt action, so that I am terminating myself" |
|
2175 |
self interruptWith:[ |
|
2176 |
self terminateWithException:aTerminateException. |
|
2177 |
]. |
|
2178 |
"maybe I am stopped - resume so that I can die" |
|
2179 |
self resume. |
|
2180 |
||
2181 |
"Created: / 23-04-2018 / 14:29:34 / stefan" |
|
2182 |
"Modified (comment): / 23-04-2018 / 15:41:07 / stefan" |
|
1 | 2183 |
! ! |
2184 |
||
21333 | 2185 |
|
6739 | 2186 |
!Process methodsFor:'thread local storage'! |
2187 |
||
19387 | 2188 |
environment |
2189 |
"return the dictionary holding thread local variables, or nil if there are none" |
|
2190 |
||
2191 |
^ environment |
|
2192 |
! |
|
2193 |
||
2194 |
environment:aDictionary |
|
2195 |
"set the dictionary holding thread local variables, or nil if there are to be none" |
|
2196 |
||
2197 |
environment := aDictionary |
|
2198 |
! |
|
2199 |
||
7427 | 2200 |
environmentAt:aKey |
2201 |
"return the value of a thread local variable, or raise an error, if no such variable exists" |
|
2202 |
||
14722 | 2203 |
^ self |
2204 |
environmentAt:aKey |
|
2205 |
ifAbsent:[ |
|
2206 |
self errorKeyNotFound:aKey. |
|
2207 |
] |
|
7427 | 2208 |
! |
2209 |
||
2210 |
environmentAt:aKey ifAbsent:defaultValue |
|
2211 |
"return the value of a thread local variable, or the value of defaultValue if no such variable exists" |
|
6739 | 2212 |
|
2213 |
|val| |
|
2214 |
||
7427 | 2215 |
environment isNil ifTrue:[^ defaultValue value]. |
2216 |
val := environment at:aKey ifAbsent:[^ defaultValue value]. |
|
6739 | 2217 |
^ val value. |
2218 |
! |
|
2219 |
||
7427 | 2220 |
environmentAt:aKey put:aValue |
2221 |
"set the value of a thread local variable. Returns aValue" |
|
2222 |
||
2223 |
|var| |
|
2224 |
||
2225 |
environment isNil ifTrue:[ |
|
20067 | 2226 |
environment := IdentityDictionary new |
7427 | 2227 |
]. |
20067 | 2228 |
var := environment at:aKey ifAbsentPut:[ValueHolder new]. |
7427 | 2229 |
var value:aValue. |
2230 |
^ aValue |
|
2231 |
! |
|
2232 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
2233 |
environmentIncludesKey:aKey |
19388 | 2234 |
"true if there is a thread local variable, false if no such variable exists" |
2235 |
||
20067 | 2236 |
^ environment notNil and:[environment includesKey:aKey] |
19388 | 2237 |
! |
2238 |
||
19377 | 2239 |
stderr |
2240 |
"the processes stderr. |
|
2241 |
By default, this is Stderr, but it can be overwritten |
|
2242 |
(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
|
2243 |
|
19377 | 2244 |
^ self environmentAt:#Stderr ifAbsent:Stderr |
2245 |
||
2246 |
" |
|
22183 | 2247 |
Processor activeProcess stderr |
19377 | 2248 |
" |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
2249 |
|
19377 | 2250 |
" |
2251 |
|out sema| |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
2252 |
|
19377 | 2253 |
out := WriteStream on:''. |
2254 |
sema := Semaphore new. |
|
2255 |
[ |
|
22183 | 2256 |
Processor activeProcess environmentAt:#Stderr put:out. |
2257 |
'hello world' errorPrintCR. |
|
2258 |
sema signal. |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
2259 |
] fork. |
19377 | 2260 |
sema wait. |
2261 |
Transcript showCR:('output was: ''',out contents,''''). |
|
2262 |
" |
|
2263 |
! |
|
2264 |
||
2265 |
stdin |
|
2266 |
"the processes stdin. |
|
2267 |
By default, this is Stdin, but it can be overwritten |
|
2268 |
(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
|
2269 |
|
19377 | 2270 |
^ self environmentAt:#Stdin ifAbsent:Stdin |
2271 |
! |
|
2272 |
||
2273 |
stdout |
|
2274 |
"the processes stdout. |
|
2275 |
By default, this is Stdout, but it can be overwritten |
|
2276 |
(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
|
2277 |
|
19377 | 2278 |
^ self environmentAt:#Stdout ifAbsent:Stdout |
2279 |
! |
|
2280 |
||
7427 | 2281 |
threadVariableValueOf:aKey |
20682 | 2282 |
"return the value of a thread local variable, |
2283 |
or nil if no such variable exists" |
|
7427 | 2284 |
|
2285 |
^ self environmentAt:aKey ifAbsent:nil |
|
16047 | 2286 |
|
2287 |
" |
|
2288 |
see example in withThreadVariable:boundTo:do: |
|
2289 |
" |
|
7427 | 2290 |
! |
2291 |
||
19377 | 2292 |
transcript |
2293 |
"the processes transcript. |
|
2294 |
By default, this is Transcript, but it can be overwritten |
|
2295 |
(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
|
2296 |
|
19380 | 2297 |
^ self environmentAt:#Transcript ifAbsent:[Transcript] |
19377 | 2298 |
! |
2299 |
||
19387 | 2300 |
withThreadLocalVariables:aDictionary do:aBlock |
2301 |
"evaluate a block with threadLocalVariables from aDictionary; |
|
2302 |
restore the old bindings afterwards." |
|
2303 |
||
2304 |
|oldEnv result| |
|
2305 |
||
2306 |
oldEnv := environment. |
|
2307 |
||
2308 |
[ |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
2309 |
environment := aDictionary. |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
2310 |
result := aBlock value. |
19387 | 2311 |
] ensure:[ |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19751
diff
changeset
|
2312 |
environment := oldEnv. |
19387 | 2313 |
]. |
2314 |
^ result |
|
2315 |
! |
|
2316 |
||
6739 | 2317 |
withThreadVariable:variableNameSymbol boundTo:aValue do:aBlock |
7427 | 2318 |
"evaluate a block with the threadLocalVariable being bound to aValue; |
2319 |
undo the variable binding afterwards." |
|
2320 |
||
23050 | 2321 |
|var oldValue| |
6739 | 2322 |
|
2323 |
environment isNil ifTrue:[ |
|
20682 | 2324 |
environment := IdentityDictionary new |
6739 | 2325 |
]. |
2326 |
var := environment at:variableNameSymbol ifAbsent:nil. |
|
2327 |
var isNil ifTrue:[ |
|
20682 | 2328 |
var := ValueHolder new. |
2329 |
environment at:variableNameSymbol put:var. |
|
6739 | 2330 |
]. |
2331 |
||
2332 |
oldValue := var value. |
|
23050 | 2333 |
^ [ |
20682 | 2334 |
var value:aValue. |
23050 | 2335 |
aBlock value. |
6739 | 2336 |
] ensure:[ |
20682 | 2337 |
oldValue isNil |
2338 |
ifTrue:[ environment removeKey:variableNameSymbol] |
|
2339 |
ifFalse:[ var value:oldValue ] |
|
6739 | 2340 |
]. |
16047 | 2341 |
|
2342 |
" |
|
2343 |
|printIt| |
|
2344 |
||
20682 | 2345 |
printIt := [ |
2346 |
Transcript |
|
2347 |
showCR:'foo is now ', |
|
2348 |
(Processor activeProcess threadVariableValueOf:#foo) printString |
|
2349 |
]. |
|
16047 | 2350 |
|
2351 |
Processor activeProcess |
|
20682 | 2352 |
withThreadVariable:#foo |
2353 |
boundTo:1234 |
|
2354 |
do:[ |
|
2355 |
printIt value. |
|
2356 |
Processor activeProcess |
|
2357 |
withThreadVariable:#foo |
|
2358 |
boundTo:2345 |
|
2359 |
do:[ |
|
2360 |
printIt value |
|
2361 |
]. |
|
2362 |
] |
|
16047 | 2363 |
" |
23050 | 2364 |
|
2365 |
"Modified: / 05-06-2018 / 16:41:11 / Stefan Vogel" |
|
6739 | 2366 |
! ! |
2367 |
||
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
2368 |
!Process class methodsFor:'documentation'! |
159 | 2369 |
|
19293 | 2370 |
version |
2371 |
^ '$Header$' |
|
2372 |
! |
|
2373 |
||
13398 | 2374 |
version_CVS |
19292 | 2375 |
^ '$Header$' |
12764
c3da6be46ff1
use _MAX_INT instead of 0x3fffffff in primitive code when generating SmallIntegers
Stefan Vogel <sv@exept.de>
parents:
11416
diff
changeset
|
2376 |
! |
c3da6be46ff1
use _MAX_INT instead of 0x3fffffff in primitive code when generating SmallIntegers
Stefan Vogel <sv@exept.de>
parents:
11416
diff
changeset
|
2377 |
|
13398 | 2378 |
version_SVN |
15964 | 2379 |
^ '$ Id: Process.st 10643 2011-06-08 21:53:07Z vranyj1 $' |
159 | 2380 |
! ! |
6774
6711472e6df4
oops - waitUntil terminated for a process that did not rune
penk
parents:
6739
diff
changeset
|
2381 |
|
15117 | 2382 |
|
699 | 2383 |
Process initialize! |