author | Claus Gittinger <cg@exept.de> |
Sat, 28 Jun 1997 17:05:51 +0200 | |
changeset 2727 | 853b7910cff2 |
parent 2726 | d54c86279d2b |
child 2839 | 22c472b4d24f |
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 |
" |
|
12 |
||
13 |
Link subclass:#Process |
|
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
14 |
instanceVariableNames:'id prio state startBlock name restartable interruptActions |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
15 |
exitActions suspendSemaphore singleStepping |
2724 | 16 |
emergencySignalHandler suspendActions creatorId processGroupId |
17 |
interruptsDisabled' |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
18 |
classVariableNames:'TerminateSignal RestartSignal CoughtSignals' |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
19 |
poolDictionaries:'' |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
20 |
category:'Kernel-Processes' |
1 | 21 |
! |
22 |
||
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
23 |
!Process class methodsFor:'documentation'! |
88 | 24 |
|
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
159 | 28 |
All Rights Reserved |
88 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
39 |
documentation |
|
40 |
" |
|
41 |
Instances of Process represent lightweight smalltalk processes |
|
42 |
(i.e. threads). These all run in a shared smalltalk/X address space, |
|
93 | 43 |
and can thus access and communicate via any objects. |
44 |
Do not confuse these with (heavy-weight) unix processes, which are |
|
45 |
created differently, and do NOT run in the same address space. |
|
46 |
Also notice, that heavy-weight process creation takes much longer. |
|
47 |
(see OperatingSystemclass>>fork). |
|
48 |
||
202 | 49 |
Processes are typically created by sending #fork or #forkAt: to a block; |
50 |
the block creates a new process, defines itself as its startBlock, |
|
51 |
and (optionally) tells the Processor about the new process. |
|
52 |
||
93 | 53 |
Scheduling is done by Processor, which is the sole instance of |
88 | 54 |
ProcessorScheduler. |
93 | 55 |
|
202 | 56 |
Processes can be terminated either soft or via a hardTerminate. |
217 | 57 |
|
202 | 58 |
A soft terminate (see Process>>terminate) will raise a TerminationSignal |
217 | 59 |
in the process, which can be handled by the process. |
60 |
If no other handler was specified, the processes own handler |
|
61 |
(see Process>>start) will catch the signal and terminate the process. |
|
62 |
During this signal processing, normal unwind processing takes place, |
|
63 |
this means that with a soft terminate, all valueOnUnwind:/valueNowOrOnUnwind: |
|
64 |
cleanup blocks are evaluated. |
|
202 | 65 |
(so a process which has set up those blocks correctly does not have to |
66 |
care especially about cleanup in case of termination). |
|
2689 | 67 |
Other than that, the TerminateSignal can be caught for special cleanup or |
217 | 68 |
even to make the process continue execution. |
202 | 69 |
|
70 |
A hard terminate (Process>>terminateNoSignal) will NOT do all of the above, |
|
71 |
but quickly (and without any cleanup) terminate the process. |
|
72 |
The debugger offers a quickTerminate option on its popupMenu for |
|
73 |
situations, when soft termination fails. (for example, if some error was |
|
74 |
coded into a handler or unwind block). |
|
75 |
||
76 |
Notice: |
|
1273 | 77 |
in Smalltalk/X, processes are gone, when an image is restarted; |
78 |
this means, that you have to take care of process re-creation yourself. |
|
79 |
Usually, this is done by depending on ObjectMemory, recreating the |
|
80 |
process(es) when the #returnFromSnapshot-change notifiction arrives. |
|
202 | 81 |
|
1273 | 82 |
All views (actually windowGroups) recreate their window process |
83 |
on image-restart. You have to do so manually for your own processes. |
|
93 | 84 |
|
85 |
A later version will allow specification of automatic restart, but |
|
217 | 86 |
thats not yet implemented. However, even when implemented, restartable processes |
87 |
will be recreated to restart from the beginning. It will not be possible to |
|
88 |
automatically continue a processes execution where it left off. |
|
89 |
This is a consequence of the portable implementation of ST/X, since in order to |
|
375 | 90 |
implement process continuation, the machines stack had to be preserved and |
91 |
recreated. Although this is possible to do (and actually not too complicated), |
|
92 |
this has not been implemented, since the machines stack layout is highly machine/compiler |
|
93 |
dependent, thus leading to much bigger porting effort of ST/X (which conflicts |
|
94 |
with ST/X's design goal of being highly portable). |
|
217 | 95 |
|
96 |
Process synchronization: |
|
1273 | 97 |
Synchronization with cooperating processes is supported as usual, |
98 |
via Semaphores (see Semaphore, Delay, SharedQueue etc.) |
|
375 | 99 |
|
1273 | 100 |
With uncooperative processes, only synchronization on suspend |
101 |
and termination is possible: |
|
102 |
any other process can wait for a process to suspend or terminate. |
|
103 |
This waiting is implemented by using suspendSemaphore and exitBlocks |
|
104 |
(where an exitSemaphore is signalled). |
|
105 |
See waitUntilSuspended / waitUntilTerminated. |
|
106 |
||
107 |
[Instance variables:] |
|
93 | 108 |
|
1273 | 109 |
id <SmallInteger> a unique process-id |
93 | 110 |
|
2197 | 111 |
creatorId <SmallInteger> the id of the process that |
112 |
created me (useful for debugging |
|
113 |
or monitoring). |
|
114 |
||
115 |
processGroupId usually the id of the creator, |
|
116 |
unless the process detached from |
|
117 |
the group and became a groupLeader. |
|
118 |
Groups can be easily terminated |
|
119 |
as a whole. |
|
120 |
Group leaders have a groupId of nil. |
|
121 |
A groupId of 0 (zero) marks a system |
|
122 |
process; these do not prevent a standAlone |
|
123 |
app from exiting. |
|
124 |
||
1273 | 125 |
prio <SmallInteger> the processes priority |
202 | 126 |
|
1273 | 127 |
state <Symbol> the processes state |
128 |
(for process-monitor) |
|
202 | 129 |
|
1273 | 130 |
startBlock <Block> the startup-block (the one that forked) |
202 | 131 |
|
1273 | 132 |
name <String-or-nil> the processes name (if any) |
133 |
(for process-monitor) |
|
202 | 134 |
|
1273 | 135 |
suspendSemaphore <Semaphore> triggered when suspend (if nonNil) |
217 | 136 |
|
2197 | 137 |
restartable <Boolean> is restartable; if true, the process |
138 |
will be restarted when an image is |
|
139 |
restarted. Otherwise, it remains dead. |
|
140 |
Running processes cannot be continued |
|
141 |
at the point where leftOff after an |
|
142 |
image-restart. |
|
202 | 143 |
|
1273 | 144 |
interruptActions <Collection> interrupt actions as defined by interruptWith:, |
145 |
performed at interrupt time |
|
202 | 146 |
|
1273 | 147 |
exitActions <Collection of Block> |
148 |
additional cleanup actions to perform |
|
149 |
on termination (if nonEmpty) |
|
202 | 150 |
|
1273 | 151 |
emergencySignalHandler <Block> can be used for per-process |
152 |
emergency signal handling |
|
2725
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
153 |
|
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
154 |
interruptsDisabled <Boolean> flag if interrupts (as installed |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
155 |
via #interruptWith:) are currently |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
156 |
disabled. (i.e. on-hold). |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
157 |
Interrupts will be delivered when |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
158 |
reenabled. |
1273 | 159 |
[Class variables:] |
159 | 160 |
|
1273 | 161 |
TerminateSignal <Signal> signal used to terminate processes |
2689 | 162 |
(should not be caught - or at least |
2197 | 163 |
rejected in handlers). |
2689 | 164 |
If caught and proceeded, a process |
2197 | 165 |
cannot be terminated via #terminate. |
166 |
For hardTermination (in case of emergency), |
|
167 |
send it a #erminateNoSignal message. |
|
168 |
||
169 |
RestartSignal <Signal> signal used to restart a process. |
|
2689 | 170 |
Can be caught in additional handler(s), |
2197 | 171 |
to perform all kind of re-initialization. |
172 |
However, these handlers should reject, |
|
173 |
for the restart to be really performed. |
|
1273 | 174 |
|
175 |
[see also:] |
|
176 |
ProcessorScheduler |
|
177 |
Block |
|
178 |
Sempahore SemaphoreSet Delay SharedQueue |
|
179 |
WindowGroup |
|
1346
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
180 |
(``Working with processes'': programming/processes.html) |
1273 | 181 |
|
1294 | 182 |
[author:] |
183 |
Claus Gittinger |
|
184 |
||
88 | 185 |
" |
213 | 186 |
! |
187 |
||
188 |
examples |
|
189 |
" |
|
190 |
start a background process, computing 1000 factorial 100 times; |
|
191 |
the processes priority is set to not disturb any interactive process. |
|
192 |
Since its prio is higher than the 3D animation demos prio, you will notice, |
|
193 |
that those are suspended while the computation runs. But Interactive views |
|
194 |
(like browsers) will continue to react normal. |
|
1316 | 195 |
[exBegin] |
213 | 196 |
[ |
197 |
'starting' printNL. |
|
198 |
100 timesRepeat:[1000 factorial]. |
|
199 |
'done with factorial' printNL. |
|
200 |
] forkAt:(Processor userBackgroundPriority). |
|
1316 | 201 |
[exEnd] |
213 | 202 |
|
203 |
||
204 |
start a background process, computing 1000 factorial 100 times; |
|
205 |
the processes priority is set to not disturb any process. |
|
206 |
The prio is set to 1 (which is the lowest possible) notice that now, |
|
207 |
the 3D animation demos also continue to run. |
|
1316 | 208 |
[exBegin] |
213 | 209 |
[ |
210 |
'starting' printNL. |
|
211 |
100 timesRepeat:[1000 factorial]. |
|
212 |
'done with factorial' printNL. |
|
213 |
] forkAt:1. |
|
1316 | 214 |
[exEnd] |
213 | 215 |
|
216 |
||
217 |
start a background process, reading a pipe without blocking other |
|
218 |
processes; |
|
1316 | 219 |
[exBegin] |
213 | 220 |
[ |
221 |
|p| |
|
222 |
||
223 |
'starting' printNL. |
|
224 |
p := PipeStream readingFrom:'ls -lR .'. |
|
225 |
[p atEnd] whileFalse:[ |
|
1316 | 226 |
p readWait. |
227 |
p nextLine printNL. |
|
213 | 228 |
]. |
229 |
p close. |
|
230 |
'done with pipe' printNL. |
|
231 |
] forkAt:1. |
|
1316 | 232 |
[exEnd] |
213 | 233 |
|
234 |
see more examples in doc/coding |
|
235 |
(or search in the browser for senders of fork*) |
|
236 |
" |
|
88 | 237 |
! ! |
1 | 238 |
|
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
239 |
!Process class methodsFor:'initialization'! |
159 | 240 |
|
241 |
initialize |
|
242 |
TerminateSignal isNil ifTrue:[ |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
243 |
TerminateSignal := Signal new mayProceed:true. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
244 |
TerminateSignal nameClass:self message:#terminateSignal. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
245 |
TerminateSignal notifierString:'unhandled process termination'. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
246 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
247 |
RestartSignal := Signal new mayProceed:true. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
248 |
RestartSignal nameClass:self message:#restartSignal. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
249 |
RestartSignal notifierString:'unhandled process restart'. |
302 | 250 |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
251 |
CoughtSignals := SignalSet |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
252 |
with:AbortSignal |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
253 |
with:TerminateSignal |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
254 |
with:RestartSignal. |
159 | 255 |
] |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
256 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
257 |
"Modified: 28.10.1996 / 20:39:05 / cg" |
159 | 258 |
! ! |
259 |
||
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
260 |
!Process class methodsFor:'instance creation'! |
699 | 261 |
|
262 |
for:aBlock priority:aPrio |
|
263 |
"create a new (unscheduled) process which will execute aBlock at |
|
264 |
a given priority, once scheduled. The process will start execution once |
|
265 |
it gets a #resume-message." |
|
266 |
||
2268
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
267 |
^ self basicNew for:aBlock priority:aPrio |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
268 |
|
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
269 |
"Modified: 25.1.1997 / 01:23:12 / cg" |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
270 |
! |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
271 |
|
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
272 |
new |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
273 |
"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
|
274 |
method, when scheduled. The process will start execution once |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
275 |
it gets a #resume-message." |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
276 |
|
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
277 |
^ self basicNew for:nil priority:(Processor activePriority). |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
278 |
|
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
279 |
"Created: 25.1.1997 / 01:31:05 / cg" |
699 | 280 |
! ! |
281 |
||
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
282 |
!Process class methodsFor:'Signal constants'! |
159 | 283 |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
284 |
restartSignal |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
285 |
"return the signal used for process restart" |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
286 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
287 |
^ RestartSignal |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
288 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
289 |
"Created: 28.10.1996 / 20:26:50 / cg" |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
290 |
! |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
291 |
|
159 | 292 |
terminateSignal |
202 | 293 |
"return the signal used for process termination" |
294 |
||
159 | 295 |
^ TerminateSignal |
296 |
! ! |
|
297 |
||
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
298 |
!Process class methodsFor:'defaults'! |
1346
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
299 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
300 |
defaultMaximumStackSize |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
301 |
"return the default max stack size. All new processes get |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
302 |
this limit initially. |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
303 |
It may be changed for individual processes with: |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
304 |
aProcess setMaximumStackSize:limit" |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
305 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
306 |
%{ /* NOCONTEXT */ |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
307 |
|
1352 | 308 |
RETURN ( __MKSMALLINT( __defaultThreadMaxStackSize() )); |
1346
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
309 |
%} |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
310 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
311 |
" |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
312 |
Process defaultMaximumStackSize |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
313 |
" |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
314 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
315 |
"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
|
316 |
! |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
317 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
318 |
defaultMaximumStackSize:numberOfBytes |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
319 |
"set the default max stack size, return the previous value. |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
320 |
All new processes get this stack limit initially. |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
321 |
It may be changed for individual processes with: |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
322 |
aProcess setMaximumStackSize:limit |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
323 |
Notice: |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
324 |
There is seldom any need to change the default setting, |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
325 |
except for highly recursive programs." |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
326 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
327 |
%{ /* NOCONTEXT */ |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
328 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
329 |
if (__isSmallInteger(numberOfBytes)) { |
1352 | 330 |
RETURN ( __MKSMALLINT( __setDefaultThreadSetMaxStackSize(__intVal(numberOfBytes)) )); |
331 |
} |
|
1346
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
332 |
%} |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
333 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
334 |
" |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
335 |
Process defaultMaximumStackSize:500*1024 |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
336 |
" |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
337 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
338 |
"Modified: 8.5.1996 / 10:23:26 / cg" |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
339 |
! ! |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
340 |
|
1980
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
341 |
!Process methodsFor:'Compatibility - V''Age'! |
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
342 |
|
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
343 |
queueInterrupt:aBlock |
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
344 |
"VisualAge compatibility: alias for #interruptWith: |
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
345 |
arrange for the receiver process to be interrupted and |
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
346 |
evaluate aBlock in its interrupt handler." |
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
347 |
|
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
348 |
^ self interruptWith:aBlock |
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
349 |
|
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
350 |
"Created: 15.11.1996 / 11:41:06 / cg" |
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
351 |
! ! |
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
352 |
|
699 | 353 |
!Process methodsFor:'accessing'! |
354 |
||
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
355 |
beGroupLeader |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
356 |
"make the receiver a processGroupLeader. |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
357 |
This detaches the process from its creator, so that it will not |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
358 |
be terminated when it teminates via #terminateGroup. |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
359 |
(windowgroup processes do this)." |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
360 |
|
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
361 |
processGroupId := id |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
362 |
|
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
363 |
"Modified: 8.7.1996 / 14:00:35 / cg" |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
364 |
"Created: 8.7.1996 / 14:08:44 / cg" |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
365 |
! |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
366 |
|
2196 | 367 |
beSystemProcess |
368 |
"make the receiver a system process. |
|
369 |
These processes have a groupId of 0. |
|
370 |
When executed as standAlone application, smalltalk exits when |
|
371 |
no more user processes are running. |
|
372 |
To prevent any daemon processes from preventing this exit, |
|
373 |
you should make the systemProcess" |
|
374 |
||
375 |
processGroupId := 0 |
|
376 |
||
377 |
"Created: 17.1.1997 / 21:42:46 / cg" |
|
378 |
! |
|
379 |
||
699 | 380 |
changePriority:aNumber |
381 |
"same as priority:, but returns the old priority. |
|
818 | 382 |
(cannot do this in #priority: for ST-80 compatibility)" |
699 | 383 |
|
384 |
|oldPrio| |
|
385 |
||
386 |
oldPrio := prio. |
|
387 |
Processor changePriority:aNumber for:self. |
|
388 |
^ oldPrio |
|
818 | 389 |
|
390 |
"Modified: 23.12.1995 / 18:38:53 / cg" |
|
699 | 391 |
! |
392 |
||
1530
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
393 |
creatorId |
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
394 |
"return the processcreators id. |
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
395 |
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
|
396 |
when debugging." |
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
397 |
|
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
398 |
^ creatorId |
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
399 |
! |
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
400 |
|
818 | 401 |
id |
402 |
"return the processes id" |
|
403 |
||
404 |
^ id |
|
405 |
! |
|
406 |
||
407 |
name |
|
408 |
"return the processes name" |
|
409 |
||
410 |
^ name |
|
411 |
! |
|
412 |
||
413 |
name:aString |
|
414 |
"set the processes name" |
|
415 |
||
416 |
name := aString |
|
417 |
! |
|
418 |
||
419 |
priority |
|
420 |
"return the receivers priority" |
|
421 |
||
422 |
^ prio |
|
423 |
! |
|
424 |
||
425 |
priority:aNumber |
|
426 |
"set my priority" |
|
427 |
||
428 |
Processor changePriority:aNumber for:self. |
|
429 |
! |
|
430 |
||
1529
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
431 |
processGroupId |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
432 |
"return the processes processGroup id. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
433 |
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
|
434 |
as the processGroup id. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
435 |
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
|
436 |
group members are terminated together. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
437 |
|
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
438 |
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
|
439 |
killed when the parent terminates (windowgroup processes do this)." |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
440 |
|
1530
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
441 |
^ processGroupId |
1529
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
442 |
|
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
443 |
"Created: 8.7.1996 / 13:47:47 / cg" |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
444 |
! |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
445 |
|
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
446 |
processGroupId:aGroupLeadersProcessID |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
447 |
"set the processes processGroup id. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
448 |
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
|
449 |
as the processGroup id. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
450 |
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
|
451 |
group members are terminated together. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
452 |
|
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
453 |
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
|
454 |
killed when the parent terminates (windowgroup processes do this)." |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
455 |
|
1530
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
456 |
processGroupId := aGroupLeadersProcessID |
1529
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
457 |
|
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
458 |
"Created: 8.7.1996 / 13:47:53 / cg" |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
459 |
! |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
460 |
|
818 | 461 |
restartable:aBoolean |
462 |
"set/clear, the restartable flag. |
|
463 |
Restartable processes will automatically be restarted by the |
|
464 |
ProcessorScheduler upon image restart. |
|
465 |
Others have to be restarted manually." |
|
466 |
||
467 |
startBlock isNil ifTrue:[ |
|
468 |
self error:'cannot be made restartable when already started'. |
|
469 |
^ self |
|
470 |
]. |
|
471 |
restartable := aBoolean |
|
472 |
||
473 |
"Modified: 23.12.1995 / 18:38:32 / cg" |
|
474 |
! |
|
475 |
||
476 |
singleStep:aBoolean |
|
477 |
singleStepping := aBoolean |
|
478 |
! |
|
479 |
||
480 |
startBlock |
|
481 |
"return the processes startup-block" |
|
482 |
||
483 |
^ startBlock |
|
484 |
! |
|
485 |
||
486 |
state |
|
487 |
"return a symbol describing the processes state" |
|
488 |
||
489 |
^ state |
|
490 |
! |
|
491 |
||
492 |
state:aSymbol |
|
493 |
"set the state - only to be used from scheduler" |
|
494 |
||
495 |
state := aSymbol |
|
496 |
! |
|
497 |
||
498 |
suspendedContext |
|
499 |
"return the processes suspended context |
|
500 |
- this is the context from which a process switch into the scheduler |
|
501 |
or another process occured. |
|
502 |
Typically, only the debugger is interested in this one." |
|
503 |
||
504 |
%{ /* NOCONTEXT */ |
|
505 |
OBJ i; |
|
506 |
||
1133 | 507 |
if (__isSmallInteger(i = __INST(id))) { |
508 |
RETURN (__threadContext(__intVal(i))); |
|
818 | 509 |
} |
510 |
%}. |
|
511 |
^ nil |
|
512 |
! ! |
|
513 |
||
514 |
!Process methodsFor:'accessing-change notifications'! |
|
515 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
516 |
addExitAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
517 |
"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
|
518 |
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
|
519 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
520 |
exitActions isNil ifTrue:[ |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
521 |
exitActions := OrderedCollection new |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
522 |
]. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
523 |
exitActions add:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
524 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
525 |
"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
|
526 |
! |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
527 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
528 |
addSuspendAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
529 |
"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
|
530 |
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
|
531 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
532 |
suspendActions isNil ifTrue:[ |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
533 |
suspendActions := OrderedCollection new |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
534 |
]. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
535 |
suspendActions add:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
536 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
537 |
"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
|
538 |
"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
|
539 |
! |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
540 |
|
699 | 541 |
emergencySignalHandler |
542 |
"return the emergencySignalHandler block. |
|
543 |
See Signal>>documentation for more info." |
|
544 |
||
545 |
^ emergencySignalHandler |
|
546 |
! |
|
547 |
||
548 |
emergencySignalHandler:aOneArgBlock |
|
549 |
"set the emergencySignalHandler block. |
|
550 |
See Signal>>documentation for more info." |
|
551 |
||
552 |
emergencySignalHandler := aOneArgBlock |
|
553 |
! |
|
554 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
555 |
removeAllExitActions |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
556 |
"remove all exit actions." |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
557 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
558 |
exitActions := nil. |
699 | 559 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
560 |
"Created: 12.1.1997 / 00:36:02 / cg" |
699 | 561 |
! |
562 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
563 |
removeAllSuspendActions |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
564 |
"remove all suspend actions." |
699 | 565 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
566 |
suspendActions := nil. |
699 | 567 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
568 |
"Created: 12.1.1997 / 00:36:16 / cg" |
818 | 569 |
! ! |
699 | 570 |
|
818 | 571 |
!Process methodsFor:'accessing-stack'! |
699 | 572 |
|
573 |
maximumStackSize |
|
574 |
"returns the processes stack limit - i.e. the process will be |
|
575 |
interrupted with a recursionSignal-raise, if it ever |
|
576 |
needs more stack (in bytes) than this number" |
|
577 |
||
578 |
%{ /* NOCONTEXT */ |
|
579 |
extern int __threadMaxStackSize(); |
|
580 |
OBJ i; |
|
581 |
||
1133 | 582 |
if (__isSmallInteger(i = __INST(id))) { |
583 |
RETURN( __MKSMALLINT(__threadMaxStackSize(__intVal(i))) ); |
|
699 | 584 |
} |
585 |
%}. |
|
586 |
^ nil |
|
587 |
! |
|
588 |
||
589 |
setMaximumStackSize:limit |
|
590 |
"sets the processes stack limit - i.e. the process will be |
|
591 |
interrupted with a recursionSignal-raise, if it ever |
|
592 |
needs more stack (in bytes) than this number. |
|
593 |
Returns the old value." |
|
594 |
||
595 |
%{ /* NOCONTEXT */ |
|
596 |
extern int __threadSetMaxStackSize(); |
|
597 |
OBJ i; |
|
598 |
||
1133 | 599 |
if (__isSmallInteger(i = __INST(id)) |
699 | 600 |
&& __isSmallInteger(limit) ) { |
1133 | 601 |
RETURN ( __MKSMALLINT(__threadSetMaxStackSize(__intVal(i), __intVal(limit))) ); |
699 | 602 |
} |
603 |
%}. |
|
604 |
^ nil |
|
605 |
! |
|
606 |
||
712
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
607 |
setStackInitialSize:initial increment:increment safe:safe |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
608 |
"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
|
609 |
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
|
610 |
|
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
611 |
%{ /* NOCONTEXT */ |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
612 |
extern int __threadSetJunkSizes(); |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
613 |
OBJ i; |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
614 |
|
1133 | 615 |
if (__isSmallInteger(i = __INST(id)) |
712
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
616 |
&& __isSmallInteger(initial) |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
617 |
&& __isSmallInteger(increment) |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
618 |
&& __isSmallInteger(safe)) { |
1133 | 619 |
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
|
620 |
} |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
621 |
%}. |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
622 |
^ false |
699 | 623 |
! ! |
624 |
||
625 |
!Process methodsFor:'interrupts'! |
|
626 |
||
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
627 |
addInterruptAction:aBlock |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
628 |
"make the receiver evaluate aBlock when resumed/interrupted. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
629 |
The name is somewhat misleading (actually, its historic): |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
630 |
the block is also evaluated on resume." |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
631 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
632 |
self uninterruptablyDo:[ |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
633 |
interruptActions isNil ifTrue:[ |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
634 |
interruptActions := OrderedCollection with:aBlock. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
635 |
] ifFalse:[ |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
636 |
interruptActions addLast:aBlock. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
637 |
]. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
638 |
]. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
639 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
640 |
"Created: 5.3.1996 / 17:10:10 / cg" |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
641 |
"Modified: 8.3.1996 / 13:03:10 / cg" |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
642 |
! |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
643 |
|
2725
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
644 |
blockInterrupts |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
645 |
"disable interrupt processing for the receiver process |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
646 |
- if disabled, incoming interrupts will be registered and handled as |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
647 |
soon as interrupts are reenabled via unblockInterrupts. |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
648 |
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
|
649 |
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
|
650 |
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
|
651 |
This is similar to OperatingSystem>>blockInterrupts, but only |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
652 |
affects interrupts for the receiver process |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
653 |
(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
|
654 |
|
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
655 |
|disabledBefore| |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
656 |
|
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
657 |
disabledBefore := interruptsDisabled. |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
658 |
interruptsDisabled := true. |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
659 |
^ disabledBefore ? false |
2726 | 660 |
|
661 |
" |
|
662 |
|p1| |
|
663 |
||
664 |
p1 := [ |
|
665 |
Transcript showCR:'disabled ...'. |
|
666 |
Transcript showCR:Processor activeProcess blockInterrupts. |
|
667 |
Transcript showCR:'busy ...'. |
|
668 |
Delay waitForSeconds:10. |
|
669 |
Transcript showCR:'enabled ...'. |
|
670 |
Processor activeProcess unblockInterrupts. |
|
671 |
] forkAt:9. |
|
672 |
||
673 |
p1 interruptWith:[Transcript showCR:'interrupted']. |
|
674 |
" |
|
2725
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
675 |
! |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
676 |
|
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
677 |
unblockInterrupts |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
678 |
"enable interrupt processing for the receiver process |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
679 |
- if any interrupts are pending, these will be handled immediately. |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
680 |
When unblocking interrupts, take care of nested block/unblock |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
681 |
calls - you should only unblock after a blockcall if they where |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
682 |
really not blocked before. |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
683 |
This is similar to OperatingSystem>>unblockInterrupts, but only |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
684 |
affects interrupts for the receiver process |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
685 |
(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
|
686 |
|
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
687 |
interruptsDisabled := false. |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
688 |
interruptActions size > 0 ifTrue:[ |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
689 |
Processor activeProcess == self ifTrue:[ |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
690 |
self interrupt |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
691 |
] |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
692 |
] |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
693 |
! |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
694 |
|
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
695 |
forceInterruptOnReturnOf:aContext |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
696 |
"helper entry for debugger. Force a stepInterrupt whenever aContext |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
697 |
returns either directly or via an unwind." |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
698 |
|
1728 | 699 |
aContext markForInterruptOnUnwind. |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
700 |
%{ |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
701 |
OBJ i; |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
702 |
|
1133 | 703 |
if (__isSmallInteger(i = __INST(id))) { |
1728 | 704 |
__threadContextStepInterrupt(__intVal(i), 1); |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
705 |
} |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
706 |
%} |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
707 |
|
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
708 |
! |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
709 |
|
699 | 710 |
interrupt |
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
711 |
"evaluate my interrupt-actions. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
712 |
The process will go back to where it got interrupted |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
713 |
after doing this." |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
714 |
|
699 | 715 |
|action| |
716 |
||
1165
c9108e9a4fdd
just to make certain: disable interrupts when removing interruptAction
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
717 |
[interruptActions size > 0] whileTrue:[ |
c9108e9a4fdd
just to make certain: disable interrupts when removing interruptAction
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
718 |
self uninterruptablyDo:[ |
c9108e9a4fdd
just to make certain: disable interrupts when removing interruptAction
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
719 |
action := interruptActions removeFirst |
c9108e9a4fdd
just to make certain: disable interrupts when removing interruptAction
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
720 |
]. |
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
721 |
action value |
699 | 722 |
]. |
723 |
interruptActions := nil |
|
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
724 |
|
1165
c9108e9a4fdd
just to make certain: disable interrupts when removing interruptAction
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
725 |
"Modified: 12.4.1996 / 12:43:31 / cg" |
699 | 726 |
! |
727 |
||
728 |
interruptWith:aBlock |
|
729 |
"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
|
730 |
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
|
731 |
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
|
732 |
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
|
733 |
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
|
734 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
735 |
Processor activeProcess == self ifTrue:[ |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
736 |
aBlock value |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
737 |
] ifFalse:[ |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
738 |
self addInterruptAction:aBlock. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
739 |
Processor scheduleForInterrupt:self. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
740 |
] |
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
741 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
742 |
"Modified: 12.1.1997 / 00:52:05 / cg" |
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
743 |
! |
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
744 |
|
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
745 |
interruptedIn:aContext |
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
746 |
"evaluate my interrupt-actions. |
2724 | 747 |
This is indirectly called by the VM, when some #interruptWith: action |
748 |
was scheduled for the process, and the process is resumed. |
|
749 |
The process will go back to where it got interrupted after doing this." |
|
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
750 |
|
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
751 |
|action| |
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
752 |
|
2727 | 753 |
"/ the returned value here has a subtle effect: |
754 |
"/ if false, the interrupt is assumed to be not taken, |
|
755 |
"/ and will be redelivered. |
|
756 |
||
2724 | 757 |
interruptsDisabled == true ifTrue:[ |
758 |
"/ no, I dont want interrupts right now; |
|
759 |
"/ try again later. |
|
760 |
^ false |
|
761 |
]. |
|
762 |
||
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
763 |
[interruptActions size > 0] whileTrue:[ |
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
764 |
self uninterruptablyDo:[ |
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
765 |
action := interruptActions removeFirst |
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
766 |
]. |
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
767 |
action numArgs == 1 ifTrue:[ |
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
768 |
action value:aContext |
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
769 |
] ifFalse:[ |
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
770 |
action value |
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
771 |
] |
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
772 |
]. |
2724 | 773 |
interruptActions := nil. |
774 |
^ true |
|
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
775 |
|
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
776 |
"Created: 18.10.1996 / 20:43:39 / cg" |
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
777 |
"Modified: 18.10.1996 / 20:47:20 / cg" |
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
778 |
! |
699 | 779 |
|
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
780 |
onResumeDo:aBlock |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
781 |
"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
|
782 |
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
|
783 |
(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
|
784 |
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
|
785 |
when it awakes." |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
786 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
787 |
self addInterruptAction:aBlock. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
788 |
Processor scheduleInterruptActionsOf:self. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
789 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
790 |
"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
|
791 |
"Modified: 8.3.1996 / 13:01:21 / cg" |
699 | 792 |
! ! |
793 |
||
794 |
!Process methodsFor:'monitoring'! |
|
795 |
||
796 |
numberOfStackBoundaryHits |
|
797 |
"internal monitoring only - will vanish" |
|
798 |
||
799 |
%{ /* NOCONTEXT */ |
|
800 |
extern int __threadNumberOfStackBoundaryHits(); |
|
801 |
int n; |
|
802 |
OBJ i; |
|
159 | 803 |
|
1133 | 804 |
if (__isSmallInteger(i = __INST(id))) { |
805 |
n = __threadNumberOfStackBoundaryHits(__intVal(i)); |
|
699 | 806 |
n &= 0x3FFFFFFF; |
1133 | 807 |
RETURN( __MKSMALLINT(n) ); |
699 | 808 |
} |
809 |
%}. |
|
810 |
^ nil |
|
811 |
! |
|
812 |
||
813 |
numberOfStackSegments |
|
814 |
"return the processes number of stack segments currently used. |
|
815 |
This method is for monitoring purposes only - it may vanish." |
|
816 |
||
817 |
%{ /* NOCONTEXT */ |
|
818 |
extern int __threadTotalStackSize(); |
|
819 |
OBJ i; |
|
820 |
||
1133 | 821 |
if (__isSmallInteger(i = __INST(id))) { |
822 |
RETURN( __MKSMALLINT(__threadStackSegments(__intVal(i))) ); |
|
699 | 823 |
} |
824 |
%}. |
|
825 |
^ nil |
|
826 |
! |
|
827 |
||
828 |
totalStackSize |
|
829 |
"return the processes maximum used stack size. |
|
830 |
This method is for monitoring purposes only - it may vanish." |
|
831 |
||
832 |
%{ /* NOCONTEXT */ |
|
833 |
extern int __threadTotalStackSize(); |
|
834 |
OBJ i; |
|
835 |
||
1133 | 836 |
if (__isSmallInteger(i = __INST(id))) { |
837 |
RETURN( __MKSMALLINT(__threadTotalStackSize(__intVal(i))) ); |
|
699 | 838 |
} |
839 |
%}. |
|
840 |
^ nil |
|
841 |
! |
|
842 |
||
843 |
usedStackSize |
|
844 |
"Return the processes current stack size. |
|
845 |
This method is for monitoring purposes only - it may vanish." |
|
846 |
||
847 |
%{ /* NOCONTEXT */ |
|
848 |
extern int __threadUsedStackSize(); |
|
849 |
OBJ i; |
|
850 |
||
1133 | 851 |
if (__isSmallInteger(i = __INST(id))) { |
852 |
RETURN( __MKSMALLINT(__threadUsedStackSize(__intVal(i))) ); |
|
699 | 853 |
} |
854 |
%}. |
|
855 |
^ nil |
|
856 |
! |
|
857 |
||
858 |
vmTrace:aBoolean |
|
859 |
"turn on/off VM message tracing for the receiver. |
|
860 |
This is meant for ST/X debugging, and may vanish. |
|
861 |
Expect lots of output, once this is turned on." |
|
862 |
||
863 |
%{ /* NOCONTEXT */ |
|
864 |
OBJ i; |
|
865 |
||
1133 | 866 |
if (__isSmallInteger(i = __INST(id))) { |
867 |
__threadTracing(__intVal(i), aBoolean); |
|
699 | 868 |
} |
869 |
%}. |
|
870 |
! ! |
|
871 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
872 |
!Process methodsFor:'obsolete'! |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
873 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
874 |
exitAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
875 |
"Obsoleted by addExitAction: / removeAllExitActions. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
876 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
877 |
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
|
878 |
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
|
879 |
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
|
880 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
881 |
self obsoleteMethodWarning:'use addExitAction: / removeAllExitActions'. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
882 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
883 |
aBlock isNil ifTrue:[ |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
884 |
^ self removeAllExitActions. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
885 |
]. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
886 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
887 |
^ self addExitAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
888 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
889 |
"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
|
890 |
"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
|
891 |
! |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
892 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
893 |
suspendAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
894 |
"Obsoleted by addSuspendAction: / removeAllSuspendActions. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
895 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
896 |
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
|
897 |
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
|
898 |
A nil argument removes all suspendActions." |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
899 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
900 |
self obsoleteMethodWarning:'use addSuspendAction: / removeAllSuspendActions'. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
901 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
902 |
aBlock isNil ifTrue:[ |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
903 |
^ self removeAllSuspendActions. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
904 |
]. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
905 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
906 |
^ self addSuspendAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
907 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
908 |
"Modified: 12.1.1997 / 00:38:22 / cg" |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
909 |
! ! |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
910 |
|
699 | 911 |
!Process methodsFor:'printing & storing'! |
912 |
||
913 |
printOn:aStream |
|
914 |
"a little more info in my printed representation" |
|
915 |
||
916 |
aStream nextPutAll:state article; |
|
917 |
space; |
|
918 |
nextPutAll:state; |
|
919 |
nextPutAll:' Process ('; |
|
920 |
nextPutAll:self nameOrId; |
|
921 |
nextPutAll:')' |
|
159 | 922 |
! ! |
923 |
||
924 |
!Process methodsFor:'private'! |
|
925 |
||
926 |
for:aBlock priority:aPrio |
|
927 |
"setup the new process - the receiver is not scheduled for |
|
928 |
execution, to get it running, send it #resume" |
|
929 |
||
339 | 930 |
|nm active| |
159 | 931 |
|
932 |
prio := aPrio. |
|
933 |
startBlock := aBlock. |
|
339 | 934 |
restartable := false. |
159 | 935 |
|
936 |
(Processor newProcessFor:self) ifFalse:[ |
|
1529
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
937 |
"for some reason, the Processor was unable to create |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
938 |
a VM process for me ...." |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
939 |
^ nil |
159 | 940 |
]. |
941 |
||
942 |
" |
|
943 |
give me a user-friendly name |
|
944 |
" |
|
339 | 945 |
active := Processor activeProcess. |
2268
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
946 |
(nm := active name) notNil ifTrue:[ |
1529
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
947 |
" |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
948 |
avoid name inflation |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
949 |
" |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
950 |
(nm endsWith:' sub') ifFalse:[ |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
951 |
nm := nm , ' [' , active id printString , '] sub' |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
952 |
]. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
953 |
name := nm |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
954 |
]. |
1530
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
955 |
processGroupId := creatorId := active id |
1529
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
956 |
|
2268
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
957 |
"Modified: 25.1.1997 / 01:28:54 / cg" |
159 | 958 |
! ! |
959 |
||
699 | 960 |
!Process methodsFor:'private scheduler access'! |
1 | 961 |
|
699 | 962 |
setId:idNumber state:stateSymbol |
963 |
"set id and state - not for public use" |
|
375 | 964 |
|
699 | 965 |
id := idNumber. |
1844 | 966 |
creatorId := processGroupId := 0. |
699 | 967 |
state := stateSymbol. |
1844 | 968 |
|
969 |
"Modified: 30.10.1996 / 00:35:29 / cg" |
|
182 | 970 |
! |
971 |
||
159 | 972 |
setPriority:aNumber |
973 |
"set priority without telling processor - not for public use" |
|
974 |
||
975 |
prio := aNumber |
|
976 |
! |
|
977 |
||
978 |
setStartBlock:aBlock |
|
979 |
"set the receivers startup block" |
|
980 |
||
981 |
startBlock := aBlock |
|
982 |
! |
|
13 | 983 |
|
159 | 984 |
setStateTo:newState if:oldState |
985 |
state == oldState ifTrue:[state := newState] |
|
986 |
! |
|
987 |
||
988 |
setStateTo:newState if:oldState1 or:oldState2 |
|
989 |
(state == oldState1 or:[state == oldState2]) ifTrue:[state := newState] |
|
699 | 990 |
! ! |
991 |
||
818 | 992 |
!Process methodsFor:'queries'! |
993 |
||
994 |
isDead |
|
995 |
"return true, iff the receiver is a dead process" |
|
996 |
||
997 |
^ (state isNil or:[state == #dead]) |
|
998 |
||
999 |
"Modified: 23.12.1995 / 18:35:29 / cg" |
|
1000 |
! |
|
1001 |
||
1002 |
isRestartable |
|
1003 |
"return true, iff the receiver is restartable" |
|
1004 |
||
1005 |
^ restartable |
|
1006 |
! |
|
1007 |
||
1008 |
isSingleStepping |
|
1009 |
^ singleStepping |
|
1010 |
! |
|
1011 |
||
2636
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1012 |
isSystemProcess |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1013 |
"return true if aProcess is a system process, |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1014 |
which should not be suspended/terminated etc.." |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1015 |
|
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1016 |
^ (Processor isPureEventDriven |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1017 |
or:[id == 0 |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1018 |
or:[processGroupId == 0 |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1019 |
or:[(Display notNil and:[Display dispatchProcess == self]) |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1020 |
]]]) |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1021 |
|
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1022 |
" |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1023 |
Processor activeProcessIsSystemProcess |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1024 |
" |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1025 |
|
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1026 |
"Created: 17.4.1997 / 12:57:37 / stefan" |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1027 |
! |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1028 |
|
818 | 1029 |
nameOrId |
1030 |
"return a string to identify the process - either name or id" |
|
1031 |
||
1032 |
name notNil ifTrue:[^ name]. |
|
1033 |
^ id printString |
|
1034 |
! ! |
|
1035 |
||
699 | 1036 |
!Process methodsFor:'special'! |
1037 |
||
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1038 |
millisecondDelay:millis |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1039 |
"suspend the current process for some time. |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1040 |
If the receiver is a system process (i.e. scheduler or event dispatcher) |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1041 |
this blocks the whole smalltalk for the time delta; |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1042 |
if its a normal thread, only that thread is suspended." |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1043 |
|
2636
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1044 |
(self isSystemProcess) ifTrue:[ |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1045 |
OperatingSystem millisecondDelay:millis |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1046 |
] ifFalse:[ |
874 | 1047 |
Delay waitForMilliseconds:millis |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1048 |
] |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1049 |
|
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1050 |
"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
|
1051 |
"Modified: 17.4.1997 / 13:02:25 / stefan" |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1052 |
! |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1053 |
|
699 | 1054 |
trapRestrictedMethods:trap |
1055 |
"Allow/deny the execution of restricted methods. |
|
1056 |
Process specific method restriction is not implemented yet, so this call is |
|
1057 |
redirected to ObjectMemory and causes a system wide restriction. |
|
1058 |
||
1059 |
Notice: method restriction is a nonstandard feature, not supported |
|
1060 |
by other smalltalk implementations and not specified in the ANSI spec. |
|
1061 |
This is EXPERIMENTAL - and being evaluated for usability. |
|
1062 |
It may change or even vanish (if it shows to be not useful)." |
|
1063 |
||
1064 |
^ObjectMemory trapRestrictedMethods:trap |
|
1065 |
||
1066 |
" |
|
1067 |
Processor activeProcess trapRestrictedMethods:true |
|
1068 |
Processor activeProcess trapRestrictedMethods:false |
|
1069 |
" |
|
1070 |
||
1071 |
"Created: 8.11.1995 / 19:45:04 / stefan" |
|
1072 |
! |
|
1073 |
||
1074 |
uninterruptablyDo:aBlock |
|
1075 |
"execute aBlock with interrupts blocked. |
|
1076 |
This does not prevent preemption by a higher priority processes |
|
1077 |
if any becomes runnable due to the evaluation of aBlock |
|
1078 |
(i.e. if a semaphore is signalled there)." |
|
1079 |
||
1080 |
"we must keep track of blocking-state if this is called nested" |
|
2302 | 1081 |
(OperatingSystem blockInterrupts) ifTrue:[ |
1082 |
"/ already blocked |
|
1083 |
^ aBlock value |
|
1084 |
]. |
|
699 | 1085 |
|
2302 | 1086 |
^ aBlock valueNowOrOnUnwindDo:[OperatingSystem unblockInterrupts] |
159 | 1087 |
! |
1088 |
||
699 | 1089 |
waitUntilSuspended |
1090 |
"wait until the receiver is suspended." |
|
1091 |
||
1033 | 1092 |
[ |
1946
370f57e569dc
oops - race in waitUntilSuspended & waitUntilTerminated
Claus Gittinger <cg@exept.de>
parents:
1844
diff
changeset
|
1093 |
self isDead ifTrue:[^ self]. |
2262 | 1094 |
suspendSemaphore isNil ifTrue:[ |
1095 |
suspendSemaphore := Semaphore new name:'process suspend' |
|
1096 |
]. |
|
1033 | 1097 |
suspendSemaphore wait |
1098 |
] valueUninterruptably |
|
699 | 1099 |
|
1946
370f57e569dc
oops - race in waitUntilSuspended & waitUntilTerminated
Claus Gittinger <cg@exept.de>
parents:
1844
diff
changeset
|
1100 |
"Modified: 8.11.1996 / 23:05:24 / cg" |
699 | 1101 |
! |
1102 |
||
1103 |
waitUntilTerminated |
|
1104 |
"wait until the receiver is terminated. |
|
1105 |
This method allows another process to wait till the receiver finishes." |
|
1106 |
||
1033 | 1107 |
|sema| |
699 | 1108 |
|
1033 | 1109 |
[ |
1946
370f57e569dc
oops - race in waitUntilSuspended & waitUntilTerminated
Claus Gittinger <cg@exept.de>
parents:
1844
diff
changeset
|
1110 |
self isDead ifTrue:[^ self]. |
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1111 |
|
2262 | 1112 |
sema := Semaphore new name:'process termination'. |
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1113 |
self addExitAction:[sema signal]. |
1033 | 1114 |
sema wait. |
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1115 |
|
1033 | 1116 |
] valueUninterruptably |
1117 |
||
1789 | 1118 |
" |
1119 |
|p| |
|
1120 |
||
1121 |
p := [10 timesRepeat:[100 factorial]] forkAt:4. |
|
1122 |
||
1123 |
Transcript showCR:'now waiting ...'. |
|
1124 |
p waitUntilTerminated. |
|
1125 |
Transcript showCR:'done.' |
|
1126 |
" |
|
1127 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1128 |
"Modified: 12.1.1997 / 00:40:59 / cg" |
699 | 1129 |
! |
1130 |
||
1131 |
withLowerPriorityDo:aBlock |
|
1132 |
"execute aBlock at a lower priority. This can be used to perform |
|
1133 |
time-consuming operations at a more user-friendly priority." |
|
159 | 1134 |
|
699 | 1135 |
^ self withPriority:(prio - 1) do:aBlock |
1136 |
||
1137 |
" |
|
1138 |
Processor activeProcess withLowerPriorityDo:[3000 factorial] |
|
1139 |
" |
|
1140 |
! |
|
1141 |
||
1142 |
withPriority:aPrio do:aBlock |
|
1143 |
"execute aBlock at another priority. This can be used to perform |
|
1144 |
time-consuming operations at a more user-friendly priority, |
|
1145 |
or some critical action at a higher priority. Do not use too high |
|
1146 |
of a priority to avoid locking up the system (event processing takes place |
|
1147 |
at 24)" |
|
1148 |
||
1149 |
|oldprio| |
|
1150 |
||
1151 |
oldprio := prio. |
|
1152 |
self priority:aPrio. |
|
1153 |
||
1154 |
^ aBlock valueNowOrOnUnwindDo:[ |
|
1155 |
self priority:oldprio |
|
1156 |
] |
|
1157 |
||
1158 |
" |
|
1159 |
Processor activeProcess withPriority:7 do:[3000 factorial] |
|
1160 |
" |
|
1161 |
"be careful - even ^C wont work until done: |
|
1162 |
Processor activeProcess withPriority:25 do:[3000 factorial] |
|
1163 |
" |
|
202 | 1164 |
! ! |
1165 |
||
1166 |
!Process methodsFor:'startup '! |
|
116 | 1167 |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1168 |
imageRestart |
699 | 1169 |
"restart the process from the beginning. |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1170 |
This is sent by the ProcessorScheduler at image restart time, |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1171 |
to all restartable processes." |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1172 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1173 |
|savedGroupId| |
699 | 1174 |
|
1175 |
"/ ('restart process ' , id printString) errorPrintNL. |
|
1176 |
||
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1177 |
savedGroupId := processGroupId. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1178 |
|
699 | 1179 |
(Processor newProcessFor:self withId:id) ifFalse:[ |
1086 | 1180 |
"for some reason, the Processor was unable to create |
1181 |
a VM process for me ...." |
|
699 | 1182 |
|
2130
b9e7e1cf98bd
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1183 |
('Process [warning]: process ' , id printString , ' failed to restart.') errorPrintCR. |
1086 | 1184 |
^ nil |
699 | 1185 |
]. |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1186 |
processGroupId := savedGroupId. |
699 | 1187 |
self resume |
1086 | 1188 |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1189 |
"Created: 28.10.1996 / 20:32:34 / cg" |
2130
b9e7e1cf98bd
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1190 |
"Modified: 10.1.1997 / 18:01:13 / cg" |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1191 |
! |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1192 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1193 |
restart |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1194 |
"restart the process from the beginning. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1195 |
This is only possible, if its restartable." |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1196 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1197 |
restartable ifFalse:[ |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1198 |
^ self error:'process is not restartable' |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1199 |
]. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1200 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1201 |
self interruptWith:[RestartSignal raise] |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1202 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1203 |
"Modified: 12.1.1997 / 00:54:32 / cg" |
699 | 1204 |
! |
1205 |
||
116 | 1206 |
start |
159 | 1207 |
"start the process - this is sent by the VM to the process to get |
1208 |
the process up and running. |
|
329 | 1209 |
Sending #start to the process (instead of directly executing the startBlock) |
1210 |
allows more flexible handling of processes, since anything that responds |
|
1211 |
to #start can be handled transparently by the VM then ..." |
|
159 | 1212 |
|
1213 |
|block| |
|
116 | 1214 |
|
159 | 1215 |
(block := startBlock) notNil ifTrue:[ |
1475 | 1216 |
" |
1217 |
just for your convenience ... |
|
1218 |
" |
|
1219 |
name isNil ifTrue:[ |
|
1220 |
name := '(' , block displayString , ')' |
|
1221 |
]. |
|
1222 |
restartable ~~ true ifTrue:[startBlock := nil]. |
|
1839 | 1223 |
|
1224 |
[ |
|
1225 |
CoughtSignals handle:[:ex | |
|
1226 |
ex signal == RestartSignal ifTrue:[ |
|
1227 |
ex restart |
|
1228 |
]. |
|
1229 |
ex return |
|
1230 |
] do:[ |
|
1231 |
block value |
|
1232 |
] |
|
1233 |
] valueOnUnwindDo:[self terminateNoSignal]. |
|
202 | 1234 |
|
1475 | 1235 |
self terminateNoSignal. |
159 | 1236 |
] ifFalse:[ |
1475 | 1237 |
"is this artificial restriction useful ?" |
1238 |
self error:'a process cannot be started twice' |
|
116 | 1239 |
] |
1475 | 1240 |
|
1839 | 1241 |
"Modified: 28.10.1996 / 21:06:45 / cg" |
1 | 1242 |
! ! |
1243 |
||
1244 |
!Process methodsFor:'suspend / resume'! |
|
1245 |
||
699 | 1246 |
resume |
1247 |
"resume the receiver process" |
|
1248 |
||
1249 |
Processor resume:self |
|
1250 |
! |
|
1251 |
||
1252 |
resumeForSingleSend |
|
1253 |
"resume the receiver process, but only let it execute a single send." |
|
1254 |
||
1255 |
Processor resumeForSingleSend:self |
|
1256 |
! |
|
1257 |
||
326 | 1258 |
stop |
1259 |
"suspend the receiver process - will continue to run when a resume is sent. |
|
1260 |
A stopped process will not be resumed for interrupt processing." |
|
1261 |
||
1262 |
state := #stopped. |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1263 |
self suspend |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1264 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1265 |
"Modified: 13.12.1995 / 13:22:58 / stefan" |
326 | 1266 |
! |
1267 |
||
1 | 1268 |
suspend |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1269 |
"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
|
1270 |
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
|
1271 |
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
|
1272 |
a suspend (see wait code in Semaphore). |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1273 |
Use #stop for a hard-suspend, which is not affected by interrupts." |
13 | 1274 |
|
1474 | 1275 |
self suspendWithState:#suspended |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1276 |
|
1474 | 1277 |
"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
|
1278 |
! |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1279 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1280 |
suspendWithState:aStateSymbol |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1281 |
"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
|
1282 |
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
|
1283 |
in the ProcessMonitor (instead of #suspended). |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1284 |
(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
|
1285 |
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
|
1286 |
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
|
1287 |
a suspend (see wait code in Semaphore). |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1288 |
Use #stop for a hard-suspend, which is not affected by interrupts." |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1289 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1290 |
suspendSemaphore notNil ifTrue:[suspendSemaphore signalForAll]. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1291 |
suspendActions notNil ifTrue:[ |
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
1292 |
suspendActions do:[:action | action value] |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1293 |
]. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1294 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1295 |
" |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1296 |
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
|
1297 |
set the state to something like #ioWait etc. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1298 |
In this case, do not set the receivers state to #suspend. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1299 |
(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
|
1300 |
" |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1301 |
(state == #active or:[state == #run]) ifTrue:[ |
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
1302 |
state := aStateSymbol. |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1303 |
]. |
1 | 1304 |
Processor suspend:self |
1305 |
! |
|
1306 |
||
1307 |
terminate |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1308 |
"terminate the receiver process. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1309 |
Termination is done by raising the terminateSignal in the receiver process, |
2689 | 1310 |
which can be caught. |
375 | 1311 |
All unwind actions and the exit-actions (if any) |
159 | 1312 |
will be performed before the process is really terminated." |
10 | 1313 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1314 |
self interruptWith:[ |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1315 |
Signal noHandlerSignal handle:[:ex | |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1316 |
ex return. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1317 |
] do:[ |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1318 |
TerminateSignal raise. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1319 |
]. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1320 |
self terminateNoSignal. |
159 | 1321 |
] |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1322 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1323 |
"Modified: 12.1.1997 / 00:55:14 / cg" |
159 | 1324 |
! |
1325 |
||
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1326 |
terminateAllSubprocesses |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1327 |
"terminate all the receivers subprocesses and their children as well |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1328 |
(i.e. all processes in the receivers process group, except for |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1329 |
the receiver itself)." |
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
1330 |
|
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
1331 |
ProcessorScheduler knownProcesses do:[:aProcess | |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
1332 |
aProcess ~~ self ifTrue:[ |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
1333 |
aProcess processGroupId == processGroupId ifTrue:[ |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1334 |
aProcess terminateWithAllSubprocesses |
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
1335 |
] |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
1336 |
] |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
1337 |
]. |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1338 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1339 |
"Modified: 28.10.1996 / 20:40:50 / cg" |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1340 |
"Created: 28.10.1996 / 20:43:32 / cg" |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1341 |
! |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1342 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1343 |
terminateGroup |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1344 |
"terminate the receiver with all of its created subprocesses |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1345 |
(i.e. all processes in the receivers process group)." |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1346 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1347 |
self terminateSubprocesses. |
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
1348 |
self terminate |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
1349 |
|
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
1350 |
"Created: 8.7.1996 / 14:04:15 / cg" |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1351 |
"Modified: 28.10.1996 / 20:42:00 / cg" |
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
1352 |
! |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
1353 |
|
159 | 1354 |
terminateNoSignal |
2197 | 1355 |
"hard-terminate the receiver process without sending a terminateSignal |
375 | 1356 |
or performing any unwind-handling. |
2197 | 1357 |
However, exit-actions are performed. |
1358 |
This is useful in case of emergency, when a buggy terminationHandler |
|
1359 |
prevents you from getting a process to terminate." |
|
375 | 1360 |
|
1361 |
|block| |
|
159 | 1362 |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1363 |
"/ this is treated like the final suspend |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1364 |
suspendActions notNil ifTrue:[ |
2384 | 1365 |
[suspendActions isEmpty] whileFalse:[ |
2197 | 1366 |
block := suspendActions removeFirst. |
1367 |
block value. |
|
1368 |
] |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1369 |
]. |
375 | 1370 |
exitActions notNil ifTrue:[ |
2384 | 1371 |
[exitActions isEmpty] whileFalse:[ |
2197 | 1372 |
block := exitActions removeFirst. |
1373 |
block value. |
|
1374 |
] |
|
375 | 1375 |
]. |
329 | 1376 |
suspendSemaphore notNil ifTrue:[suspendSemaphore signalForAll]. |
159 | 1377 |
Processor terminateNoSignal:self |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1378 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1379 |
"Modified: 13.12.1995 / 13:40:14 / stefan" |
2384 | 1380 |
"Modified: 12.2.1997 / 12:41:38 / cg" |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1381 |
! |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1382 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1383 |
terminateSubprocesses |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1384 |
"terminate all the receivers subprocesses |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1385 |
(i.e. all processes in the receivers process group, except for |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1386 |
the receiver itself)." |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1387 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1388 |
ProcessorScheduler knownProcesses do:[:aProcess | |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1389 |
aProcess ~~ self ifTrue:[ |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1390 |
aProcess processGroupId == processGroupId ifTrue:[ |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1391 |
aProcess terminate |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1392 |
] |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1393 |
] |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1394 |
]. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1395 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1396 |
"Modified: 28.10.1996 / 20:40:50 / cg" |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1397 |
"Created: 28.10.1996 / 20:41:49 / cg" |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1398 |
! |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1399 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1400 |
terminateWithAllSubprocesses |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1401 |
"terminate the receiver with all of its created subprocesses and their children |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1402 |
(i.e. all processes in the receivers process group)." |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1403 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1404 |
self terminateAllSubprocesses. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1405 |
self terminate |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1406 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1407 |
"Modified: 28.10.1996 / 20:42:00 / cg" |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1408 |
"Created: 28.10.1996 / 20:44:07 / cg" |
1 | 1409 |
! ! |
1410 |
||
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
1411 |
!Process class methodsFor:'documentation'! |
159 | 1412 |
|
699 | 1413 |
version |
2727 | 1414 |
^ '$Header: /cvs/stx/stx/libbasic/Process.st,v 1.82 1997-06-28 15:05:51 cg Exp $' |
159 | 1415 |
! ! |
699 | 1416 |
Process initialize! |