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