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