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