author | Claus Gittinger <cg@exept.de> |
Wed, 28 Feb 1996 21:39:36 +0100 | |
changeset 1033 | 244530001e84 |
parent 1000 | 0e7c3cc79792 |
child 1086 | 7b0641a2e1ef |
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 |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
16 |
emergencySignalHandler suspendActions' |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
17 |
classVariableNames:'TerminateSignal CoughtSignals' |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
18 |
poolDictionaries:'' |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
19 |
category:'Kernel-Processes' |
1 | 20 |
! |
21 |
||
88 | 22 |
!Process class methodsFor:'documentation'! |
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
159 | 27 |
All Rights Reserved |
88 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
40 |
Instances of Process represent lightweight smalltalk processes |
|
41 |
(i.e. threads). These all run in a shared smalltalk/X address space, |
|
93 | 42 |
and can thus access and communicate via any objects. |
43 |
Do not confuse these with (heavy-weight) unix processes, which are |
|
44 |
created differently, and do NOT run in the same address space. |
|
45 |
Also notice, that heavy-weight process creation takes much longer. |
|
46 |
(see OperatingSystemclass>>fork). |
|
47 |
||
202 | 48 |
Processes are typically created by sending #fork or #forkAt: to a block; |
49 |
the block creates a new process, defines itself as its startBlock, |
|
50 |
and (optionally) tells the Processor about the new process. |
|
51 |
||
93 | 52 |
Scheduling is done by Processor, which is the sole instance of |
88 | 53 |
ProcessorScheduler. |
93 | 54 |
|
202 | 55 |
Processes can be terminated either soft or via a hardTerminate. |
217 | 56 |
|
202 | 57 |
A soft terminate (see Process>>terminate) will raise a TerminationSignal |
217 | 58 |
in the process, which can be handled by the process. |
59 |
If no other handler was specified, the processes own handler |
|
60 |
(see Process>>start) will catch the signal and terminate the process. |
|
61 |
During this signal processing, normal unwind processing takes place, |
|
62 |
this means that with a soft terminate, all valueOnUnwind:/valueNowOrOnUnwind: |
|
63 |
cleanup blocks are evaluated. |
|
202 | 64 |
(so a process which has set up those blocks correctly does not have to |
65 |
care especially about cleanup in case of termination). |
|
217 | 66 |
Other than that, the TerminateSignal can be cought for special cleanup or |
67 |
even to make the process continue execution. |
|
202 | 68 |
|
69 |
A hard terminate (Process>>terminateNoSignal) will NOT do all of the above, |
|
70 |
but quickly (and without any cleanup) terminate the process. |
|
71 |
The debugger offers a quickTerminate option on its popupMenu for |
|
72 |
situations, when soft termination fails. (for example, if some error was |
|
73 |
coded into a handler or unwind block). |
|
74 |
||
75 |
Notice: |
|
76 |
in Smalltalk/X, processes are gone, when an image is restarted; |
|
77 |
this means, that you have to take care of process re-creation yourself. |
|
78 |
Usually, this is done by depending on ObjectMemory, recreating the |
|
375 | 79 |
process(es) when the #returnFromSnapshot-change notifiction arrives. |
202 | 80 |
|
81 |
All views (actually windowGroups) recreate their window process |
|
82 |
on image-restart. You have to do so manually for your own processes. |
|
93 | 83 |
|
84 |
A later version will allow specification of automatic restart, but |
|
217 | 85 |
thats not yet implemented. However, even when implemented, restartable processes |
86 |
will be recreated to restart from the beginning. It will not be possible to |
|
87 |
automatically continue a processes execution where it left off. |
|
88 |
This is a consequence of the portable implementation of ST/X, since in order to |
|
375 | 89 |
implement process continuation, the machines stack had to be preserved and |
90 |
recreated. Although this is possible to do (and actually not too complicated), |
|
91 |
this has not been implemented, since the machines stack layout is highly machine/compiler |
|
92 |
dependent, thus leading to much bigger porting effort of ST/X (which conflicts |
|
93 |
with ST/X's design goal of being highly portable). |
|
217 | 94 |
|
95 |
Process synchronization: |
|
375 | 96 |
Synchronization with cooperating processes is supported as usual, |
97 |
via Semaphores (see Semaphore, Delay, SharedQueue etc.) |
|
98 |
||
99 |
With uncooperative processes, only synchronization on suspend |
|
100 |
and termination is possible: |
|
101 |
any other process can wait for a process to suspend or terminate. |
|
102 |
This waiting is implemented by using suspendSemaphore and exitBlocks |
|
103 |
(where an exitSemaphore is signalled). |
|
104 |
See waitUntilSuspended / waitUntilTerminated. |
|
93 | 105 |
|
106 |
Instance variables: |
|
107 |
||
159 | 108 |
id <SmallInteger> a unique process-id |
202 | 109 |
|
159 | 110 |
prio <SmallInteger> the processes priority |
202 | 111 |
|
159 | 112 |
state <Symbol> the processes state |
113 |
(for process-monitor) |
|
202 | 114 |
|
115 |
startBlock <Block> the startup-block (the one that forked) |
|
116 |
||
159 | 117 |
name <String-or-nil> the processes name (if any) |
118 |
(for process-monitor) |
|
202 | 119 |
|
217 | 120 |
suspendSemaphore <Semaphore> triggered when suspend (if nonNil) |
121 |
||
159 | 122 |
restartable <Boolean> is restartable (not yet implemented) |
202 | 123 |
|
159 | 124 |
interruptActions <Collection> interrupt actions as defined by interruptWith:, |
125 |
performed at interrupt time |
|
202 | 126 |
|
375 | 127 |
exitActions <Collection of Block> |
128 |
additional cleanup actions to perform |
|
129 |
on termination (if nonEmpty) |
|
202 | 130 |
|
159 | 131 |
emergencySignalHandler <Block> can be used for per-process |
132 |
emergency signal handling |
|
133 |
Class variables: |
|
134 |
||
135 |
TerminateSignal <Signal> signal used to terminate processes |
|
136 |
(should not be cought - or at least |
|
137 |
rejected in handlers) |
|
88 | 138 |
" |
213 | 139 |
! |
140 |
||
141 |
examples |
|
142 |
" |
|
143 |
start a background process, computing 1000 factorial 100 times; |
|
144 |
the processes priority is set to not disturb any interactive process. |
|
145 |
Since its prio is higher than the 3D animation demos prio, you will notice, |
|
146 |
that those are suspended while the computation runs. But Interactive views |
|
147 |
(like browsers) will continue to react normal. |
|
148 |
||
149 |
[ |
|
150 |
'starting' printNL. |
|
151 |
100 timesRepeat:[1000 factorial]. |
|
152 |
'done with factorial' printNL. |
|
153 |
] forkAt:(Processor userBackgroundPriority). |
|
154 |
||
155 |
||
156 |
start a background process, computing 1000 factorial 100 times; |
|
157 |
the processes priority is set to not disturb any process. |
|
158 |
The prio is set to 1 (which is the lowest possible) notice that now, |
|
159 |
the 3D animation demos also continue to run. |
|
160 |
||
161 |
[ |
|
162 |
'starting' printNL. |
|
163 |
100 timesRepeat:[1000 factorial]. |
|
164 |
'done with factorial' printNL. |
|
165 |
] forkAt:1. |
|
166 |
||
167 |
||
168 |
start a background process, reading a pipe without blocking other |
|
169 |
processes; |
|
170 |
||
171 |
[ |
|
172 |
|p| |
|
173 |
||
174 |
'starting' printNL. |
|
175 |
p := PipeStream readingFrom:'ls -lR .'. |
|
176 |
[p atEnd] whileFalse:[ |
|
177 |
p readWait. |
|
178 |
p nextLine printNL. |
|
179 |
]. |
|
180 |
p close. |
|
181 |
'done with pipe' printNL. |
|
182 |
] forkAt:1. |
|
183 |
||
184 |
see more examples in doc/coding |
|
185 |
(or search in the browser for senders of fork*) |
|
186 |
" |
|
88 | 187 |
! ! |
1 | 188 |
|
159 | 189 |
!Process class methodsFor:'initialization'! |
190 |
||
191 |
initialize |
|
192 |
TerminateSignal isNil ifTrue:[ |
|
193 |
TerminateSignal := Signal new mayProceed:true. |
|
194 |
TerminateSignal nameClass:self message:#terminateSignal. |
|
195 |
TerminateSignal notifierString:'unhandled process termination'. |
|
302 | 196 |
|
197 |
CoughtSignals := SignalSet with:AbortSignal with:TerminateSignal. |
|
159 | 198 |
] |
199 |
! ! |
|
200 |
||
699 | 201 |
!Process class methodsFor:'instance creation'! |
202 |
||
203 |
for:aBlock priority:aPrio |
|
204 |
"create a new (unscheduled) process which will execute aBlock at |
|
205 |
a given priority, once scheduled. The process will start execution once |
|
206 |
it gets a #resume-message." |
|
207 |
||
208 |
^ self new for:aBlock priority:aPrio |
|
209 |
! ! |
|
210 |
||
345 | 211 |
!Process class methodsFor:'Signal constants'! |
159 | 212 |
|
213 |
terminateSignal |
|
202 | 214 |
"return the signal used for process termination" |
215 |
||
159 | 216 |
^ TerminateSignal |
217 |
! ! |
|
218 |
||
699 | 219 |
!Process methodsFor:'accessing'! |
220 |
||
221 |
changePriority:aNumber |
|
222 |
"same as priority:, but returns the old priority. |
|
818 | 223 |
(cannot do this in #priority: for ST-80 compatibility)" |
699 | 224 |
|
225 |
|oldPrio| |
|
226 |
||
227 |
oldPrio := prio. |
|
228 |
Processor changePriority:aNumber for:self. |
|
229 |
^ oldPrio |
|
818 | 230 |
|
231 |
"Modified: 23.12.1995 / 18:38:53 / cg" |
|
699 | 232 |
! |
233 |
||
818 | 234 |
id |
235 |
"return the processes id" |
|
236 |
||
237 |
^ id |
|
238 |
! |
|
239 |
||
240 |
name |
|
241 |
"return the processes name" |
|
242 |
||
243 |
^ name |
|
244 |
! |
|
245 |
||
246 |
name:aString |
|
247 |
"set the processes name" |
|
248 |
||
249 |
name := aString |
|
250 |
! |
|
251 |
||
252 |
priority |
|
253 |
"return the receivers priority" |
|
254 |
||
255 |
^ prio |
|
256 |
! |
|
257 |
||
258 |
priority:aNumber |
|
259 |
"set my priority" |
|
260 |
||
261 |
Processor changePriority:aNumber for:self. |
|
262 |
! |
|
263 |
||
264 |
restartable:aBoolean |
|
265 |
"set/clear, the restartable flag. |
|
266 |
Restartable processes will automatically be restarted by the |
|
267 |
ProcessorScheduler upon image restart. |
|
268 |
Others have to be restarted manually." |
|
269 |
||
270 |
startBlock isNil ifTrue:[ |
|
271 |
self error:'cannot be made restartable when already started'. |
|
272 |
^ self |
|
273 |
]. |
|
274 |
restartable := aBoolean |
|
275 |
||
276 |
"Modified: 23.12.1995 / 18:38:32 / cg" |
|
277 |
! |
|
278 |
||
279 |
singleStep:aBoolean |
|
280 |
singleStepping := aBoolean |
|
281 |
! |
|
282 |
||
283 |
startBlock |
|
284 |
"return the processes startup-block" |
|
285 |
||
286 |
^ startBlock |
|
287 |
! |
|
288 |
||
289 |
state |
|
290 |
"return a symbol describing the processes state" |
|
291 |
||
292 |
^ state |
|
293 |
! |
|
294 |
||
295 |
state:aSymbol |
|
296 |
"set the state - only to be used from scheduler" |
|
297 |
||
298 |
state := aSymbol |
|
299 |
! |
|
300 |
||
301 |
suspendedContext |
|
302 |
"return the processes suspended context |
|
303 |
- this is the context from which a process switch into the scheduler |
|
304 |
or another process occured. |
|
305 |
Typically, only the debugger is interested in this one." |
|
306 |
||
307 |
%{ /* NOCONTEXT */ |
|
308 |
OBJ i; |
|
309 |
||
310 |
if (__isSmallInteger(i = _INST(id))) { |
|
311 |
RETURN (__threadContext(_intVal(i))); |
|
312 |
} |
|
313 |
%}. |
|
314 |
^ nil |
|
315 |
! ! |
|
316 |
||
317 |
!Process methodsFor:'accessing-change notifications'! |
|
318 |
||
699 | 319 |
emergencySignalHandler |
320 |
"return the emergencySignalHandler block. |
|
321 |
See Signal>>documentation for more info." |
|
322 |
||
323 |
^ emergencySignalHandler |
|
324 |
! |
|
325 |
||
326 |
emergencySignalHandler:aOneArgBlock |
|
327 |
"set the emergencySignalHandler block. |
|
328 |
See Signal>>documentation for more info." |
|
329 |
||
330 |
emergencySignalHandler := aOneArgBlock |
|
331 |
! |
|
332 |
||
333 |
exitAction:aBlock |
|
334 |
"add aBlock to the processes exit actions. |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
335 |
This block will be evaluated right before the process dies. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
336 |
An argument of nil clears removes all exitActions." |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
337 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
338 |
aBlock isNil ifTrue:[ |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
339 |
exitActions := nil. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
340 |
^ self. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
341 |
]. |
699 | 342 |
|
343 |
exitActions isNil ifTrue:[ |
|
344 |
exitActions := OrderedCollection new |
|
345 |
]. |
|
346 |
exitActions add:aBlock |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
347 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
348 |
"Modified: 13.12.1995 / 13:44:03 / stefan" |
699 | 349 |
! |
350 |
||
818 | 351 |
suspendAction:aBlock |
352 |
"add aBlock to the processes suspend actions. |
|
353 |
This block will be evaluated when a process gets suspended. |
|
354 |
A nil argument removes all suspendActions." |
|
699 | 355 |
|
818 | 356 |
aBlock isNil ifTrue:[ |
357 |
suspendActions := nil. |
|
358 |
^ self. |
|
359 |
]. |
|
699 | 360 |
|
818 | 361 |
suspendActions isNil ifTrue:[ |
362 |
suspendActions := OrderedCollection new |
|
363 |
]. |
|
364 |
suspendActions add:aBlock |
|
699 | 365 |
|
818 | 366 |
"Created: 13.12.1995 / 13:35:54 / stefan" |
367 |
"Modified: 13.12.1995 / 13:44:31 / stefan" |
|
368 |
! ! |
|
699 | 369 |
|
818 | 370 |
!Process methodsFor:'accessing-stack'! |
699 | 371 |
|
372 |
maximumStackSize |
|
373 |
"returns the processes stack limit - i.e. the process will be |
|
374 |
interrupted with a recursionSignal-raise, if it ever |
|
375 |
needs more stack (in bytes) than this number" |
|
376 |
||
377 |
%{ /* NOCONTEXT */ |
|
378 |
extern int __threadMaxStackSize(); |
|
379 |
OBJ i; |
|
380 |
||
381 |
if (__isSmallInteger(i = _INST(id))) { |
|
382 |
RETURN( _MKSMALLINT(__threadMaxStackSize(_intVal(i))) ); |
|
383 |
} |
|
384 |
%}. |
|
385 |
^ nil |
|
386 |
! |
|
387 |
||
388 |
setMaximumStackSize:limit |
|
389 |
"sets the processes stack limit - i.e. the process will be |
|
390 |
interrupted with a recursionSignal-raise, if it ever |
|
391 |
needs more stack (in bytes) than this number. |
|
392 |
Returns the old value." |
|
393 |
||
394 |
%{ /* NOCONTEXT */ |
|
395 |
extern int __threadSetMaxStackSize(); |
|
396 |
OBJ i; |
|
397 |
||
398 |
if (__isSmallInteger(i = _INST(id)) |
|
399 |
&& __isSmallInteger(limit) ) { |
|
400 |
RETURN ( _MKSMALLINT(__threadSetMaxStackSize(_intVal(i), _intVal(limit))) ); |
|
401 |
} |
|
402 |
%}. |
|
403 |
^ nil |
|
404 |
! |
|
405 |
||
712
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
406 |
setStackInitialSize:initial increment:increment safe:safe |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
407 |
"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
|
408 |
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
|
409 |
|
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
410 |
%{ /* NOCONTEXT */ |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
411 |
extern int __threadSetJunkSizes(); |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
412 |
OBJ i; |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
413 |
|
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
414 |
if (__isSmallInteger(i = _INST(id)) |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
415 |
&& __isSmallInteger(initial) |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
416 |
&& __isSmallInteger(increment) |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
417 |
&& __isSmallInteger(safe)) { |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
418 |
RETURN ( __threadSetJunkSizes(_intVal(i), _intVal(initial), _intVal(increment), _intVal(safe)) ? true : false ); |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
419 |
} |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
420 |
%}. |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
421 |
^ false |
699 | 422 |
! ! |
423 |
||
424 |
!Process methodsFor:'interrupts'! |
|
425 |
||
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
426 |
forceInterruptOnReturnOf:aContext |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
427 |
"helper entry for debugger. Force a stepInterrupt whenever aContext |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
428 |
returns either directly or via an unwind." |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
429 |
|
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
430 |
aContext markForUnwind. |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
431 |
%{ |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
432 |
OBJ i; |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
433 |
|
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
434 |
if (__isSmallInteger(i = _INST(id))) { |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
435 |
__threadContextStepInterrupt(__intVal(i), 1); |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
436 |
} |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
437 |
%} |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
438 |
|
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
439 |
! |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
440 |
|
699 | 441 |
interrupt |
442 |
"evaluate my interrupt-actions |
|
443 |
the process will go back to where it got interrupted |
|
444 |
after doing this. |
|
445 |
" |
|
446 |
|action| |
|
447 |
||
448 |
[interruptActions notNil and:[interruptActions notEmpty]] whileTrue:[ |
|
449 |
action := interruptActions removeFirst. |
|
450 |
action value |
|
451 |
]. |
|
452 |
interruptActions := nil |
|
453 |
! |
|
454 |
||
455 |
interruptWith:aBlock |
|
456 |
"interrupt the receiver and make it evaluate aBlock. |
|
457 |
If the receiver is currently suspended, the block will be remembered |
|
458 |
to be evaluated once the receiver wakes up." |
|
459 |
||
460 |
self uninterruptablyDo:[ |
|
461 |
interruptActions isNil ifTrue:[ |
|
462 |
interruptActions := OrderedCollection with:aBlock. |
|
463 |
] ifFalse:[ |
|
464 |
interruptActions addLast:aBlock. |
|
465 |
]. |
|
466 |
]. |
|
467 |
Processor scheduleForInterrupt:self. |
|
468 |
! ! |
|
469 |
||
470 |
!Process methodsFor:'monitoring'! |
|
471 |
||
472 |
numberOfStackBoundaryHits |
|
473 |
"internal monitoring only - will vanish" |
|
474 |
||
475 |
%{ /* NOCONTEXT */ |
|
476 |
extern int __threadNumberOfStackBoundaryHits(); |
|
477 |
int n; |
|
478 |
OBJ i; |
|
159 | 479 |
|
699 | 480 |
if (__isSmallInteger(i = _INST(id))) { |
481 |
n = __threadNumberOfStackBoundaryHits(_intVal(i)); |
|
482 |
n &= 0x3FFFFFFF; |
|
483 |
RETURN( _MKSMALLINT(n) ); |
|
484 |
} |
|
485 |
%}. |
|
486 |
^ nil |
|
487 |
! |
|
488 |
||
489 |
numberOfStackSegments |
|
490 |
"return the processes number of stack segments currently used. |
|
491 |
This method is for monitoring purposes only - it may vanish." |
|
492 |
||
493 |
%{ /* NOCONTEXT */ |
|
494 |
extern int __threadTotalStackSize(); |
|
495 |
OBJ i; |
|
496 |
||
497 |
if (__isSmallInteger(i = _INST(id))) { |
|
498 |
RETURN( _MKSMALLINT(__threadStackSegments(_intVal(i))) ); |
|
499 |
} |
|
500 |
%}. |
|
501 |
^ nil |
|
502 |
! |
|
503 |
||
504 |
totalStackSize |
|
505 |
"return the processes maximum used stack size. |
|
506 |
This method is for monitoring purposes only - it may vanish." |
|
507 |
||
508 |
%{ /* NOCONTEXT */ |
|
509 |
extern int __threadTotalStackSize(); |
|
510 |
OBJ i; |
|
511 |
||
512 |
if (__isSmallInteger(i = _INST(id))) { |
|
513 |
RETURN( _MKSMALLINT(__threadTotalStackSize(_intVal(i))) ); |
|
514 |
} |
|
515 |
%}. |
|
516 |
^ nil |
|
517 |
! |
|
518 |
||
519 |
usedStackSize |
|
520 |
"Return the processes current stack size. |
|
521 |
This method is for monitoring purposes only - it may vanish." |
|
522 |
||
523 |
%{ /* NOCONTEXT */ |
|
524 |
extern int __threadUsedStackSize(); |
|
525 |
OBJ i; |
|
526 |
||
527 |
if (__isSmallInteger(i = _INST(id))) { |
|
528 |
RETURN( _MKSMALLINT(__threadUsedStackSize(_intVal(i))) ); |
|
529 |
} |
|
530 |
%}. |
|
531 |
^ nil |
|
532 |
! |
|
533 |
||
534 |
vmTrace:aBoolean |
|
535 |
"turn on/off VM message tracing for the receiver. |
|
536 |
This is meant for ST/X debugging, and may vanish. |
|
537 |
Expect lots of output, once this is turned on." |
|
538 |
||
539 |
%{ /* NOCONTEXT */ |
|
540 |
OBJ i; |
|
541 |
||
542 |
if (__isSmallInteger(i = _INST(id))) { |
|
543 |
__threadTracing(_intVal(i), aBoolean); |
|
544 |
} |
|
545 |
%}. |
|
546 |
! ! |
|
547 |
||
548 |
!Process methodsFor:'printing & storing'! |
|
549 |
||
550 |
printOn:aStream |
|
551 |
"a little more info in my printed representation" |
|
552 |
||
553 |
aStream nextPutAll:state article; |
|
554 |
space; |
|
555 |
nextPutAll:state; |
|
556 |
nextPutAll:' Process ('; |
|
557 |
nextPutAll:self nameOrId; |
|
558 |
nextPutAll:')' |
|
159 | 559 |
! ! |
560 |
||
561 |
!Process methodsFor:'private'! |
|
562 |
||
563 |
for:aBlock priority:aPrio |
|
564 |
"setup the new process - the receiver is not scheduled for |
|
565 |
execution, to get it running, send it #resume" |
|
566 |
||
339 | 567 |
|nm active| |
159 | 568 |
|
569 |
prio := aPrio. |
|
570 |
startBlock := aBlock. |
|
339 | 571 |
restartable := false. |
159 | 572 |
|
573 |
(Processor newProcessFor:self) ifFalse:[ |
|
574 |
"for some reason, the Processor was unable to create |
|
575 |
a VM process for me ...." |
|
576 |
^ nil |
|
577 |
]. |
|
578 |
||
579 |
" |
|
580 |
give me a user-friendly name |
|
581 |
" |
|
339 | 582 |
active := Processor activeProcess. |
583 |
(nm := active name) notNil ifTrue:[ |
|
159 | 584 |
" |
585 |
avoid name inflation |
|
586 |
" |
|
314 | 587 |
(nm endsWith:' sub') ifFalse:[ |
339 | 588 |
nm := nm , ' [' , active id printString , '] sub' |
159 | 589 |
]. |
590 |
name := nm |
|
591 |
] |
|
592 |
! ! |
|
593 |
||
699 | 594 |
!Process methodsFor:'private scheduler access'! |
1 | 595 |
|
699 | 596 |
setId:idNumber state:stateSymbol |
597 |
"set id and state - not for public use" |
|
375 | 598 |
|
699 | 599 |
id := idNumber. |
600 |
state := stateSymbol. |
|
182 | 601 |
! |
602 |
||
159 | 603 |
setPriority:aNumber |
604 |
"set priority without telling processor - not for public use" |
|
605 |
||
606 |
prio := aNumber |
|
607 |
! |
|
608 |
||
609 |
setStartBlock:aBlock |
|
610 |
"set the receivers startup block" |
|
611 |
||
612 |
startBlock := aBlock |
|
613 |
! |
|
13 | 614 |
|
159 | 615 |
setStateTo:newState if:oldState |
616 |
state == oldState ifTrue:[state := newState] |
|
617 |
! |
|
618 |
||
619 |
setStateTo:newState if:oldState1 or:oldState2 |
|
620 |
(state == oldState1 or:[state == oldState2]) ifTrue:[state := newState] |
|
699 | 621 |
! ! |
622 |
||
818 | 623 |
!Process methodsFor:'queries'! |
624 |
||
625 |
isDead |
|
626 |
"return true, iff the receiver is a dead process" |
|
627 |
||
628 |
^ (state isNil or:[state == #dead]) |
|
629 |
||
630 |
"Modified: 23.12.1995 / 18:35:29 / cg" |
|
631 |
! |
|
632 |
||
633 |
isRestartable |
|
634 |
"return true, iff the receiver is restartable" |
|
635 |
||
636 |
^ restartable |
|
637 |
! |
|
638 |
||
639 |
isSingleStepping |
|
640 |
^ singleStepping |
|
641 |
! |
|
642 |
||
643 |
nameOrId |
|
644 |
"return a string to identify the process - either name or id" |
|
645 |
||
646 |
name notNil ifTrue:[^ name]. |
|
647 |
^ id printString |
|
648 |
! ! |
|
649 |
||
699 | 650 |
!Process methodsFor:'special'! |
651 |
||
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
652 |
millisecondDelay:millis |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
653 |
"suspend the current process for some time. |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
654 |
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
|
655 |
this blocks the whole smalltalk for the time delta; |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
656 |
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
|
657 |
|
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
658 |
(Processor isSystemProcess:self) ifTrue:[ |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
659 |
OperatingSystem millisecondDelay:millis |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
660 |
] ifFalse:[ |
874 | 661 |
Delay waitForMilliseconds:millis |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
662 |
] |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
663 |
|
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
664 |
"Created: 16.12.1995 / 13:10:53 / cg" |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
665 |
! |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
666 |
|
699 | 667 |
trapRestrictedMethods:trap |
668 |
"Allow/deny the execution of restricted methods. |
|
669 |
Process specific method restriction is not implemented yet, so this call is |
|
670 |
redirected to ObjectMemory and causes a system wide restriction. |
|
671 |
||
672 |
Notice: method restriction is a nonstandard feature, not supported |
|
673 |
by other smalltalk implementations and not specified in the ANSI spec. |
|
674 |
This is EXPERIMENTAL - and being evaluated for usability. |
|
675 |
It may change or even vanish (if it shows to be not useful)." |
|
676 |
||
677 |
^ObjectMemory trapRestrictedMethods:trap |
|
678 |
||
679 |
" |
|
680 |
Processor activeProcess trapRestrictedMethods:true |
|
681 |
Processor activeProcess trapRestrictedMethods:false |
|
682 |
" |
|
683 |
||
684 |
"Created: 8.11.1995 / 19:45:04 / stefan" |
|
685 |
! |
|
686 |
||
687 |
uninterruptablyDo:aBlock |
|
688 |
"execute aBlock with interrupts blocked. |
|
689 |
This does not prevent preemption by a higher priority processes |
|
690 |
if any becomes runnable due to the evaluation of aBlock |
|
691 |
(i.e. if a semaphore is signalled there)." |
|
692 |
||
693 |
|wasBlocked| |
|
694 |
||
695 |
"we must keep track of blocking-state if this is called nested" |
|
696 |
||
697 |
wasBlocked := OperatingSystem blockInterrupts. |
|
698 |
^ aBlock valueNowOrOnUnwindDo:[ |
|
699 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
700 |
0 "stc hint" |
|
701 |
] |
|
159 | 702 |
! |
703 |
||
699 | 704 |
waitUntilSuspended |
705 |
"wait until the receiver is suspended." |
|
706 |
||
1033 | 707 |
[ |
708 |
suspendSemaphore isNil ifTrue:[suspendSemaphore := Semaphore new]. |
|
709 |
suspendSemaphore wait |
|
710 |
] valueUninterruptably |
|
699 | 711 |
|
1033 | 712 |
"Modified: 28.2.1996 / 21:38:00 / cg" |
699 | 713 |
! |
714 |
||
715 |
waitUntilTerminated |
|
716 |
"wait until the receiver is terminated. |
|
717 |
This method allows another process to wait till the receiver finishes." |
|
718 |
||
1033 | 719 |
|sema| |
699 | 720 |
|
1033 | 721 |
[ |
722 |
sema := Semaphore new. |
|
723 |
self exitAction:[sema signal]. |
|
724 |
sema wait. |
|
725 |
] valueUninterruptably |
|
726 |
||
727 |
"Modified: 28.2.1996 / 21:38:21 / cg" |
|
699 | 728 |
! |
729 |
||
730 |
withLowerPriorityDo:aBlock |
|
731 |
"execute aBlock at a lower priority. This can be used to perform |
|
732 |
time-consuming operations at a more user-friendly priority." |
|
159 | 733 |
|
699 | 734 |
^ self withPriority:(prio - 1) do:aBlock |
735 |
||
736 |
" |
|
737 |
Processor activeProcess withLowerPriorityDo:[3000 factorial] |
|
738 |
" |
|
739 |
! |
|
740 |
||
741 |
withPriority:aPrio do:aBlock |
|
742 |
"execute aBlock at another priority. This can be used to perform |
|
743 |
time-consuming operations at a more user-friendly priority, |
|
744 |
or some critical action at a higher priority. Do not use too high |
|
745 |
of a priority to avoid locking up the system (event processing takes place |
|
746 |
at 24)" |
|
747 |
||
748 |
|oldprio| |
|
749 |
||
750 |
oldprio := prio. |
|
751 |
self priority:aPrio. |
|
752 |
||
753 |
^ aBlock valueNowOrOnUnwindDo:[ |
|
754 |
self priority:oldprio |
|
755 |
] |
|
756 |
||
757 |
" |
|
758 |
Processor activeProcess withPriority:7 do:[3000 factorial] |
|
759 |
" |
|
760 |
"be careful - even ^C wont work until done: |
|
761 |
Processor activeProcess withPriority:25 do:[3000 factorial] |
|
762 |
" |
|
202 | 763 |
! ! |
764 |
||
765 |
!Process methodsFor:'startup '! |
|
116 | 766 |
|
699 | 767 |
restart |
768 |
"restart the process from the beginning. |
|
769 |
This is sent by the ProcessorScheduler to all restartable processes." |
|
770 |
||
771 |
"/ ('restart process ' , id printString) errorPrintNL. |
|
772 |
||
773 |
(Processor newProcessFor:self withId:id) ifFalse:[ |
|
774 |
"for some reason, the Processor was unable to create |
|
775 |
a VM process for me ...." |
|
776 |
||
777 |
('process ' , id printString , ' failed to restart.') errorPrintNL. |
|
778 |
^ nil |
|
779 |
]. |
|
780 |
self resume |
|
781 |
! |
|
782 |
||
116 | 783 |
start |
159 | 784 |
"start the process - this is sent by the VM to the process to get |
785 |
the process up and running. |
|
329 | 786 |
Sending #start to the process (instead of directly executing the startBlock) |
787 |
allows more flexible handling of processes, since anything that responds |
|
788 |
to #start can be handled transparently by the VM then ..." |
|
159 | 789 |
|
790 |
|block| |
|
116 | 791 |
|
159 | 792 |
(block := startBlock) notNil ifTrue:[ |
793 |
" |
|
794 |
just for your convenience ... |
|
795 |
" |
|
796 |
name isNil ifTrue:[ |
|
359 | 797 |
name := '(' , block displayString , ')' |
159 | 798 |
]. |
329 | 799 |
restartable ~~ true ifTrue:[startBlock := nil]. |
302 | 800 |
CoughtSignals handle:[:ex | |
159 | 801 |
ex return |
182 | 802 |
] do:block. |
202 | 803 |
|
375 | 804 |
self terminateNoSignal. |
159 | 805 |
] ifFalse:[ |
806 |
"is this artificial restriction useful ?" |
|
807 |
self error:'a process cannot be started twice' |
|
116 | 808 |
] |
1 | 809 |
! ! |
810 |
||
811 |
!Process methodsFor:'suspend / resume'! |
|
812 |
||
699 | 813 |
resume |
814 |
"resume the receiver process" |
|
815 |
||
816 |
Processor resume:self |
|
817 |
! |
|
818 |
||
819 |
resumeForSingleSend |
|
820 |
"resume the receiver process, but only let it execute a single send." |
|
821 |
||
822 |
Processor resumeForSingleSend:self |
|
823 |
! |
|
824 |
||
326 | 825 |
stop |
826 |
"suspend the receiver process - will continue to run when a resume is sent. |
|
827 |
A stopped process will not be resumed for interrupt processing." |
|
828 |
||
829 |
state := #stopped. |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
830 |
self suspend |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
831 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
832 |
"Modified: 13.12.1995 / 13:22:58 / stefan" |
326 | 833 |
! |
834 |
||
1 | 835 |
suspend |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
836 |
"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
|
837 |
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
|
838 |
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
|
839 |
a suspend (see wait code in Semaphore). |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
840 |
Use #stop for a hard-suspend, which is not affected by interrupts." |
13 | 841 |
|
329 | 842 |
suspendSemaphore notNil ifTrue:[suspendSemaphore signalForAll]. |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
843 |
suspendActions notNil ifTrue:[ |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
844 |
suspendActions do:[:action | action value] |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
845 |
]. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
846 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
847 |
" |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
848 |
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
|
849 |
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
|
850 |
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
|
851 |
(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
|
852 |
" |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
853 |
(state == #active or:[state == #run]) ifTrue:[ |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
854 |
state := #suspended |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
855 |
]. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
856 |
Processor suspend:self |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
857 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
858 |
"Modified: 13.12.1995 / 14:20:26 / stefan" |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
859 |
! |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
860 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
861 |
suspendWithState:aStateSymbol |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
862 |
"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
|
863 |
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
|
864 |
in the ProcessMonitor (instead of #suspended). |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
865 |
(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
|
866 |
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
|
867 |
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
|
868 |
a suspend (see wait code in Semaphore). |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
869 |
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
|
870 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
871 |
suspendSemaphore notNil ifTrue:[suspendSemaphore signalForAll]. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
872 |
suspendActions notNil ifTrue:[ |
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
873 |
suspendActions do:[:action | action value] |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
874 |
]. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
875 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
876 |
" |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
877 |
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
|
878 |
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
|
879 |
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
|
880 |
(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
|
881 |
" |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
882 |
(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
|
883 |
state := aStateSymbol. |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
884 |
]. |
1 | 885 |
Processor suspend:self |
886 |
! |
|
887 |
||
888 |
terminate |
|
375 | 889 |
"terminate the receiver process. Termination is done by raising |
890 |
the terminateSignal in the receiver process, which can be cought. |
|
891 |
All unwind actions and the exit-actions (if any) |
|
159 | 892 |
will be performed before the process is really terminated." |
10 | 893 |
|
159 | 894 |
Processor activeProcess == self ifTrue:[ |
895 |
Signal noHandlerSignal handle:[:ex | |
|
896 |
ex return. |
|
897 |
] do:[ |
|
898 |
TerminateSignal raise. |
|
899 |
]. |
|
375 | 900 |
self terminateNoSignal. |
159 | 901 |
] ifFalse:[ |
902 |
self interruptWith:[self terminate] |
|
903 |
] |
|
904 |
! |
|
905 |
||
906 |
terminateNoSignal |
|
375 | 907 |
"terminate the receiver process without sending a terminateSignal |
908 |
or performing any unwind-handling. |
|
909 |
However, exit-actions are performed." |
|
910 |
||
911 |
|block| |
|
159 | 912 |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
913 |
"/ this is treated like the final suspend |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
914 |
suspendActions notNil ifTrue:[ |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
915 |
[suspendActions notEmpty] whileTrue:[ |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
916 |
block := suspendActions removeFirst. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
917 |
block value. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
918 |
] |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
919 |
]. |
375 | 920 |
exitActions notNil ifTrue:[ |
921 |
[exitActions notEmpty] whileTrue:[ |
|
922 |
block := exitActions removeFirst. |
|
923 |
block value. |
|
924 |
] |
|
925 |
]. |
|
329 | 926 |
suspendSemaphore notNil ifTrue:[suspendSemaphore signalForAll]. |
159 | 927 |
Processor terminateNoSignal:self |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
928 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
929 |
"Modified: 13.12.1995 / 13:40:14 / stefan" |
1 | 930 |
! ! |
931 |
||
699 | 932 |
!Process class methodsFor:'documentation'! |
159 | 933 |
|
699 | 934 |
version |
1033 | 935 |
^ '$Header: /cvs/stx/stx/libbasic/Process.st,v 1.44 1996-02-28 20:38:42 cg Exp $' |
159 | 936 |
! ! |
699 | 937 |
Process initialize! |