Process.st
branchjv
changeset 20078 a680abc90e84
parent 19863 513bd7237fe7
parent 19969 654d2e1a2dc4
child 20081 2961b4289773
equal deleted inserted replaced
20077:e0e720fce465 20078:a680abc90e84
    41 !
    41 !
    42 
    42 
    43 documentation
    43 documentation
    44 "
    44 "
    45     WARNING:
    45     WARNING:
    46 	the offsets of the instance variables lookupActivations and lookupDisabled are known in the VM
    46         the offsets of the instance variables lookupActivations and lookupDisabled are known in the VM
    47 	do not remove them, and do not insert/remove instance variables before them
    47         do not remove them, and do not insert/remove instance variables before them
    48 
    48 
    49     Instances of Process represent lightweight smalltalk processes
    49     Instances of Process represent lightweight smalltalk processes
    50     (i.e. threads). These all run in a shared smalltalk/X address space,
    50     (i.e. threads). These all run in a shared smalltalk/X address space,
    51     and can thus access and communicate via any objects.
    51     and can thus access and communicate via any objects.
    52     Do not confuse these with (heavy-weight) unix processes, which are
    52     Do not confuse these with (heavy-weight) unix processes, which are
    96 
    96 
    97     Leaving the processes startBlock has the same effct as a soft-terminate
    97     Leaving the processes startBlock has the same effct as a soft-terminate
    98     (i.e. there is no need to send an explicit terminate).
    98     (i.e. there is no need to send an explicit terminate).
    99 
    99 
   100     Notice:
   100     Notice:
   101 	in Smalltalk/X, processes are gone, when an image is restarted;
   101         in Smalltalk/X, processes are gone, when an image is restarted;
   102 	this means, that you have to take care of process re-creation yourself.
   102         this means, that you have to take care of process re-creation yourself.
   103 	Usually, this is done by depending on ObjectMemory, recreating the
   103         Usually, this is done by depending on ObjectMemory, recreating the
   104 	process(es) when the #returnFromSnapshot-change notifiction arrives.
   104         process(es) when the #returnFromSnapshot-change notifiction arrives.
   105 
   105 
   106 	All views (actually windowGroups) recreate their window process
   106         All views (actually windowGroups) recreate their window process
   107 	on image-restart. You have to do so manually for your own processes.
   107         on image-restart. You have to do so manually for your own processes.
   108 
   108 
   109     A later version will allow specification of automatic restart, but
   109     A later version will allow specification of automatic restart, but
   110     that's not yet implemented. However, even when implemented, restartable processes
   110     that's not yet implemented. However, even when implemented, restartable processes
   111     will be recreated to restart from the beginning. It will not be possible to
   111     will be recreated to restart from the beginning. It will not be possible to
   112     automatically continue a processes execution where it left off.
   112     automatically continue a processes execution where it left off.
   116     this has not been implemented, since the machines stack layout is highly machine/compiler
   116     this has not been implemented, since the machines stack layout is highly machine/compiler
   117     dependent, thus leading to much bigger porting effort of ST/X (which conflicts
   117     dependent, thus leading to much bigger porting effort of ST/X (which conflicts
   118     with ST/X's design goal of being highly portable).
   118     with ST/X's design goal of being highly portable).
   119 
   119 
   120     Process synchronization:
   120     Process synchronization:
   121 	Synchronization with cooperating processes is supported as usual,
   121         Synchronization with cooperating processes is supported as usual,
   122 	via Semaphores (see Semaphore, Delay, SharedQueue etc.)
   122         via Semaphores (see Semaphore, Delay, SharedQueue etc.)
   123 
   123 
   124 	With uncooperative processes, only synchronization on suspend
   124         With uncooperative processes, only synchronization on suspend
   125 	and termination is possible:
   125         and termination is possible:
   126 	  any other process can wait for a process to suspend or terminate.
   126           any other process can wait for a process to suspend or terminate.
   127 	  This waiting is implemented by using suspendSemaphore and exitBlocks
   127           This waiting is implemented by using suspendSemaphore and exitBlocks
   128 	  (where an exitSemaphore is signalled).
   128           (where an exitSemaphore is signalled).
   129 	  See waitUntilSuspended / waitUntilTerminated.
   129           See waitUntilSuspended / waitUntilTerminated.
   130 
   130 
   131 
   131     Implementation note:
       
   132         for historic and compatibility reasons, Process is a subclass of Link,
       
   133         which means, that instances are directly usable as nodes in a linkedList.
       
   134         However, this also means, that processes can only be elements of a single LinkedList.
       
   135         This is somewhat dangerous, as unknowledgable programmers may unwillingly break the
       
   136         scheduler, by placing a process onto another linked list.
       
   137         Therefore, we plan to change this in the future.
       
   138         
   132     Process states:
   139     Process states:
   133 	#dead           process has (been) terminated;
   140         #dead           process has (been) terminated;
   134 			the process instance has no underlting
   141                         the process instance has no underlting
   135 			thread.
   142                         thread.
   136 
   143 
   137 	#run            the process is willing to run,
   144         #run            the process is willing to run,
   138 			but not active (i.e. another higher prio
   145                         but not active (i.e. another higher prio
   139 			process is currently executing)
   146                         process is currently executing)
   140 
   147 
   141 	#active         the process is the current process
   148         #active         the process is the current process
   142 			(there is only one)
   149                         (there is only one)
   143 
   150 
   144 	#ioWait         waiting on some io-related semaphore
   151         #ioWait         waiting on some io-related semaphore
   145 			(typically in #readWait / #writeWait)
   152                         (typically in #readWait / #writeWait)
   146 
   153 
   147 	#eventWait      waiting on some GUI event
   154         #eventWait      waiting on some GUI event
   148 
   155 
   149 	#timeWait       waiting on a timer-related semaphore
   156         #timeWait       waiting on a timer-related semaphore
   150 
   157 
   151 	#wait           waiting on some (other) semaphore
   158         #wait           waiting on some (other) semaphore
   152 
   159 
   153 	#suspended      stopped from execution; however, an interrupt
   160         #suspended      stopped from execution; however, an interrupt
   154 			will return it into the run state.
   161                         will return it into the run state.
   155 
   162 
   156 	#stopped        stopped from execution; an interrupt will
   163         #stopped        stopped from execution; an interrupt will
   157 			NOT return it into the run state (for debugging)
   164                         NOT return it into the run state (for debugging)
   158 
   165 
   159 	#debug          debugger sitting on top of the processes
   166         #debug          debugger sitting on top of the processes
   160 			stack.
   167                         stack.
   161 
   168 
   162     Win32 only:
   169     Win32 only:
   163 
   170 
   164 	#osWait         waiting on an OS-API call to finish.
   171         #osWait         waiting on an OS-API call to finish.
   165 			can be interrupted, terminated and aborted
   172                         can be interrupted, terminated and aborted
   166 			(i.e. the usual context actions are is possible).
   173                         (i.e. the usual context actions are is possible).
   167 
   174 
   168 	#halted         thread was caught while in a blocking API call
   175         #halted         thread was caught while in a blocking API call
   169 			or primitive endless loop and has been halted by
   176                         or primitive endless loop and has been halted by
   170 			the scheduler.
   177                         the scheduler.
   171 			Can only be resumed or hard-terminated - abort
   178                         Can only be resumed or hard-terminated - abort
   172 			or soft terminate or unwind actions are not possible.
   179                         or soft terminate or unwind actions are not possible.
   173 			(due to win32 limitations)
   180                         (due to win32 limitations)
   174 
   181 
   175 
   182 
   176     [Instance variables:]
   183     [Instance variables:]
   177 
   184 
   178 	id                     <SmallInteger>   a unique process-id
   185         id                     <SmallInteger>   a unique process-id
   179 
   186 
   180 	creatorId              <SmallInteger>   the id of the process that
   187         creatorId              <SmallInteger>   the id of the process that
   181 						created me (useful for debugging
   188                                                 created me (useful for debugging
   182 						or monitoring).
   189                                                 or monitoring).
   183 
   190 
   184 	processGroupId                          usually the id of the creator,
   191         processGroupId                          usually the id of the creator,
   185 						unless the process detached from
   192                                                 unless the process detached from
   186 						the group and became a groupLeader.
   193                                                 the group and became a groupLeader.
   187 						Groups can be easily terminated
   194                                                 Groups can be easily terminated
   188 						as a whole.
   195                                                 as a whole.
   189 						Group leaders have a groupId of nil.
   196                                                 Group leaders have a groupId of nil.
   190 						A groupId of 0 (zero) marks a system
   197                                                 A groupId of 0 (zero) marks a system
   191 						process; these do not prevent a standAlone
   198                                                 process; these do not prevent a standAlone
   192 						app from exiting.
   199                                                 app from exiting.
   193 
   200 
   194 	prio                   <SmallInteger>   the processes priority
   201         prio                   <SmallInteger>   the processes priority
   195 
   202 
   196 	priorityRange          <Interval>       the processes dynamic priority range
   203         priorityRange          <Interval>       the processes dynamic priority range
   197 						(or nil)
   204                                                 (or nil)
   198 
   205 
   199 	state                  <Symbol>         the processes state
   206         state                  <Symbol>         the processes state
   200 						(for process-monitor)
   207                                                 (for process-monitor)
   201 
   208 
   202 	startBlock             <Block>          the startup-block (the one that forked)
   209         startBlock             <Block>          the startup-block (the one that forked)
   203 
   210 
   204 	name                   <String-or-nil>  the processes name (if any)
   211         name                   <String-or-nil>  the processes name (if any)
   205 						(for process-monitor)
   212                                                 (for process-monitor)
   206 
   213 
   207 	suspendSemaphore       <Semaphore>      triggered when suspend (if nonNil)
   214         suspendSemaphore       <Semaphore>      triggered when suspend (if nonNil)
   208 
   215 
   209 	restartable            <Boolean>        is restartable; if true, the process
   216         restartable            <Boolean>        is restartable; if true, the process
   210 						will be restarted when an image is
   217                                                 will be restarted when an image is
   211 						restarted. Otherwise, it remains dead.
   218                                                 restarted. Otherwise, it remains dead.
   212 						Running processes cannot be continued
   219                                                 Running processes cannot be continued
   213 						at the point where leftOff after an
   220                                                 at the point where leftOff after an
   214 						image-restart.
   221                                                 image-restart.
   215 
   222 
   216 	interruptActions       <Collection>     interrupt actions as defined by interruptWith:,
   223         interruptActions       <Collection>     interrupt actions as defined by interruptWith:,
   217 						performed at interrupt time
   224                                                 performed at interrupt time
   218 
   225 
   219 	exitActions            <Collection of Block>
   226         exitActions            <Collection of Block>
   220 						additional cleanup actions to perform
   227                                                 additional cleanup actions to perform
   221 						on termination (if nonEmpty)
   228                                                 on termination (if nonEmpty)
   222 
   229 
   223 	emergencySignalHandler <Block>          can be used for per-process
   230         emergencySignalHandler <Block>          can be used for per-process
   224 						emergency signal handling
   231                                                 emergency signal handling
   225 
   232 
   226 	interruptsDisabled     <Boolean>        flag if interrupts (as installed
   233         interruptsDisabled     <Boolean>        flag if interrupts (as installed
   227 						via #interruptWith:) are currently
   234                                                 via #interruptWith:) are currently
   228 						disabled. (i.e. on-hold).
   235                                                 disabled. (i.e. on-hold).
   229 						Interrupts will be delivered when
   236                                                 Interrupts will be delivered when
   230 						reenabled.
   237                                                 reenabled.
   231 
   238 
   232 	exceptionHandlerSet    <ExceptionhandlerSet>
   239         exceptionHandlerSet    <ExceptionhandlerSet>
   233 						Handled by any process; allows for
   240                                                 Handled by any process; allows for
   234 						exceptionHandlers and query-answerers to
   241                                                 exceptionHandlers and query-answerers to
   235 						be added/removed dynamically.
   242                                                 be added/removed dynamically.
   236 
   243 
   237     [Class variables:]
   244     [Class variables:]
   238 
   245 
   239 	TerminateSignal         <Signal>        signal used to terminate processes
   246         TerminateSignal         <Signal>        signal used to terminate processes
   240 						(should not be caught - or at least
   247                                                 (should not be caught - or at least
   241 						 rejected in handlers).
   248                                                  rejected in handlers).
   242 						If caught and proceeded, a process
   249                                                 If caught and proceeded, a process
   243 						cannot be terminated via #terminate.
   250                                                 cannot be terminated via #terminate.
   244 						For hardTermination (in case of emergency),
   251                                                 For hardTermination (in case of emergency),
   245 						send it a #erminateNoSignal message.
   252                                                 send it a #erminateNoSignal message.
   246 
   253 
   247 	RestartSignal           <Signal>        signal used to restart a process.
   254         RestartSignal           <Signal>        signal used to restart a process.
   248 						Can be caught in additional handler(s),
   255                                                 Can be caught in additional handler(s),
   249 						to perform all kind of re-initialization.
   256                                                 to perform all kind of re-initialization.
   250 						However, these handlers should reject,
   257                                                 However, these handlers should reject,
   251 						for the restart to be really performed.
   258                                                 for the restart to be really performed.
   252 
   259 
   253     [see also:]
   260     [see also:]
   254 	ProcessorScheduler
   261         ProcessorScheduler
   255 	Block
   262         Block
   256 	Sempahore SemaphoreSet Delay SharedQueue
   263         Sempahore SemaphoreSet Delay SharedQueue
   257 	WindowGroup
   264         WindowGroup
   258 	(``Working with processes'': programming/processes.html)
   265         (``Working with processes'': programming/processes.html)
   259 
   266 
   260     [author:]
   267     [author:]
   261 	Claus Gittinger
   268         Claus Gittinger
   262 
   269 
   263 "
   270 "
   264 !
   271 !
   265 
   272 
   266 examples
   273 examples
   521 
   528 
   522     ^ self interruptWith:aBlock
   529     ^ self interruptWith:aBlock
   523 
   530 
   524     "Created: 15.11.1996 / 11:41:06 / cg"
   531     "Created: 15.11.1996 / 11:41:06 / cg"
   525 ! !
   532 ! !
       
   533 
   526 
   534 
   527 !Process methodsFor:'accessing'!
   535 !Process methodsFor:'accessing'!
   528 
   536 
   529 beGUIProcess
   537 beGUIProcess
   530     "mark the receiver as a gui process.
   538     "mark the receiver as a gui process.
  2092 
  2100 
  2093     "Modified: 28.10.1996 / 20:42:00 / cg"
  2101     "Modified: 28.10.1996 / 20:42:00 / cg"
  2094     "Created: 28.10.1996 / 20:44:07 / cg"
  2102     "Created: 28.10.1996 / 20:44:07 / cg"
  2095 ! !
  2103 ! !
  2096 
  2104 
       
  2105 
  2097 !Process methodsFor:'thread local storage'!
  2106 !Process methodsFor:'thread local storage'!
  2098 
  2107 
  2099 environment
  2108 environment
  2100     "return the dictionary holding thread local variables, or nil if there are none"
  2109     "return the dictionary holding thread local variables, or nil if there are none"
  2101 
  2110