ProcessorScheduler.st
changeset 14943 141d20b16378
parent 14780 113129e94917
child 14954 359f1b2de055
--- a/ProcessorScheduler.st	Mon Mar 25 13:13:09 2013 +0100
+++ b/ProcessorScheduler.st	Mon Mar 25 13:15:24 2013 +0100
@@ -21,7 +21,8 @@
 		osChildExitActions gotChildSignalInterrupt
 		exitWhenNoMoreUserProcesses suspendScheduler timeSliceProcess
 		supportDynamicPriorities timeSliceNeededSemaphore
-		scheduledProcesses preWaitActions timeoutHandlerProcess'
+		scheduledProcesses preWaitActions timeoutHandlerProcess
+		readableResultFdArray writableResultFdArray'
 	classVariableNames:'KnownProcesses KnownProcessIds PureEventDriven
 		UserSchedulingPriority UserInterruptPriority TimingPriority
 		HighestPriority SchedulingPriority MaxNumberOfProcesses
@@ -437,8 +438,8 @@
 knownProcessesDo:aBlock
     "evaluate aBlock for each (living) processes in the system"
 
-    KnownProcesses do:[:p | 
-        (p notNil and:[p ~~ 0]) ifTrue:[aBlock value:p]
+    KnownProcesses do:[:p |
+	(p notNil and:[p ~~ 0]) ifTrue:[aBlock value:p]
     ]
 
     "Created: / 26-10-2012 / 13:02:33 / cg"
@@ -601,7 +602,7 @@
 
     wasBlocked := OperatingSystem blockInterrupts.
     idleActions isNil ifTrue:[
-        idleActions := OrderedCollection new
+	idleActions := OrderedCollection new
     ].
     idleActions add:aBlock.
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
@@ -814,8 +815,8 @@
     "avoid confusion if entered twice"
 
     dispatching == true ifTrue:[
-        'Processor [info]: already in dispatch' infoPrintCR.
-        ^ self
+	'Processor [info]: already in dispatch' infoPrintCR.
+	^ self
     ].
     dispatching := true.
 
@@ -827,21 +828,21 @@
     dispatchAction := [self dispatch].
 
     handlerAction := [:ex |
-                        ('Processor [info]: ignored signal (', ex signal printString, ')') infoPrintCR.
-                        ex return
-                     ].
+			('Processor [info]: ignored signal (', ex signal printString, ')') infoPrintCR.
+			ex return
+		     ].
 
     ignoredSignals := SignalSet
-                        with:TerminateProcessRequest
-                        with:RecursionError
-                        with:AbortAllOperationRequest.
+			with:TerminateProcessRequest
+			with:RecursionError
+			with:AbortAllOperationRequest.
 
     "/
     "/ I made this an extra call to dispatch; this allows recompilation
     "/  of the dispatch-handling code in the running system.
     "/
     [dispatching] whileTrue:[
-        ignoredSignals handle:handlerAction do:dispatchAction
+	ignoredSignals handle:handlerAction do:dispatchAction
     ].
 
     "/ we arrive here in standalone Apps,
@@ -993,44 +994,44 @@
     |index pri aProcess l|
 
     OperatingSystem interruptsBlocked ifFalse:[
-        MiniDebugger
-            enterWithMessage:'vmResumeInterrupt with no interruptsBlocked'
-            mayProceed:true.
+	MiniDebugger
+	    enterWithMessage:'vmResumeInterrupt with no interruptsBlocked'
+	    mayProceed:true.
     ].
 
     index := KnownProcessIds identityIndexOf:id.
     index ~~ 0 ifTrue:[
-        aProcess := KnownProcesses at:index.
-        pri := aProcess priority.
-        l := quiescentProcessLists at:pri.
-        l notNil ifTrue:[
-            (l includesIdentical:aProcess) ifTrue:[
-                "/ aProcess is on a run queue.
-                "/ CG: this situation may happen, if the wrapCall
-                "/ finishes before the process was layed to sleep
-                "/ (i.e. schedulerIRQ arrives before the threadSwitch was finished).
-                "/ In that case, simply resume it and everything is OK.
-                "/ If the process is state running, ignore.
-
-                |state|
-
-                state := aProcess state.
-                (state == #wrapWait or:[state == #osWait] or:[state == #stopped]) ifTrue:[
-                    aProcess state:#run.
-                ].
-                'ProcSched [info]: resumeIRQ ignored for process: ' infoPrint.
-                aProcess id infoPrint. ' in state: ' infoPrint. state infoPrintCR.
-                ^ self
-            ]
-        ] ifFalse:[
-            l := LinkedList new.
-            quiescentProcessLists at:pri put:l.
-        ].
-        l addLast:aProcess.
-        aProcess state:#run.
+	aProcess := KnownProcesses at:index.
+	pri := aProcess priority.
+	l := quiescentProcessLists at:pri.
+	l notNil ifTrue:[
+	    (l includesIdentical:aProcess) ifTrue:[
+		"/ aProcess is on a run queue.
+		"/ CG: this situation may happen, if the wrapCall
+		"/ finishes before the process was layed to sleep
+		"/ (i.e. schedulerIRQ arrives before the threadSwitch was finished).
+		"/ In that case, simply resume it and everything is OK.
+		"/ If the process is state running, ignore.
+
+		|state|
+
+		state := aProcess state.
+		(state == #wrapWait or:[state == #osWait] or:[state == #stopped]) ifTrue:[
+		    aProcess state:#run.
+		].
+		'ProcSched [info]: resumeIRQ ignored for process: ' infoPrint.
+		aProcess id infoPrint. ' in state: ' infoPrint. state infoPrintCR.
+		^ self
+	    ]
+	] ifFalse:[
+	    l := LinkedList new.
+	    quiescentProcessLists at:pri put:l.
+	].
+	l addLast:aProcess.
+	aProcess state:#run.
     ] ifFalse:[
-        'ProcSched [info]: resumeIRQ for unknown process: ' infoPrint.
-        id infoPrintCR.
+	'ProcSched [info]: resumeIRQ for unknown process: ' infoPrint.
+	id infoPrintCR.
     ]
 
     "Modified: / 28.9.1998 / 11:36:53 / cg"
@@ -1047,19 +1048,19 @@
     |pri l newState|
 
     OperatingSystem interruptsBlocked ifFalse:[
-        MiniDebugger
-            enterWithMessage:'immediateInterrupt with no interruptsBlocked'
-            mayProceed:true.
+	MiniDebugger
+	    enterWithMessage:'immediateInterrupt with no interruptsBlocked'
+	    mayProceed:true.
     ].
 
     (whyCode == 2) ifTrue:[
-         newState := #wrapWait.
+	 newState := #wrapWait.
     ] ifFalse:[
-        (whyCode == 3) ifTrue:[
-            newState := #osWait.
-        ] ifFalse:[
-            newState := #stopped.
-        ].
+	(whyCode == 3) ifTrue:[
+	    newState := #osWait.
+	] ifFalse:[
+	    newState := #stopped.
+	].
     ].
     activeProcess setStateTo:newState if:#active.
 
@@ -1070,9 +1071,9 @@
      the ifAbsent block, because [] is a shared cheap block, created at compile time
     "
     (l isNil or:[(l removeIdentical:activeProcess ifAbsent:nil) isNil]) ifTrue:[
-        "/ 'Processor [warning]: bad vmSuspendInterrupt: not on run list' errorPrintCR.
-        MiniDebugger enterWithMessage:'bad vmSuspendInterrupt: not on run list' mayProceed:true.
-        ^ self
+	"/ 'Processor [warning]: bad vmSuspendInterrupt: not on run list' errorPrintCR.
+	MiniDebugger enterWithMessage:'bad vmSuspendInterrupt: not on run list' mayProceed:true.
+	^ self
     ].
 ! !
 
@@ -1297,9 +1298,9 @@
     extern OBJ ___threadSwitch();
 
     if (__isSmallInteger(id)) {
-        ok = ___threadSwitch(__context, __intVal(id), (singleStep == true) ? 1 : 0, 0);
+	ok = ___threadSwitch(__context, __intVal(id), (singleStep == true) ? 1 : 0, 0);
     } else {
-        ok = false;
+	ok = false;
     }
 %}.
 
@@ -1312,40 +1313,40 @@
     currentPriority := oldProcess priority.
 
     ok == true ifFalse:[
-        "
-         switch failed for some reason -
-         destroy (hard-terminate) the bad process.
-         This happens when:
-         - the stack went above the absolute limit
-           (VM switches back to scheduler)
-         - a halted process cannot execute its interrupt
-           actions (win32 only)
-        "
-        (id := p id) ~~ 0 ifTrue:[
-            id notNil ifTrue:[
-                'Processor [warning]: problem with process ' errorPrint.
-                id errorPrint.
-                (nm := p name) notNil ifTrue:[
-                    ' (' errorPrint. nm errorPrint. ')' errorPrint.
-                ].
-
-                ok == #halted ifTrue:[
-                    "/ that process was halted (win32 only)
-                    p state:#halted.
-                   '; stopped it.' errorPrintCR.
-                   self suspend:p.
-                ] ifFalse:[
-                   '; hard-terminate it.' errorPrintCR.
-                   'Processor [info]: cleanup may take a while if stack is huge' infoPrintCR.
-                   p state:#cleanup.
-                   self terminateNoSignal:p.
-                ]
-            ]
-        ]
+	"
+	 switch failed for some reason -
+	 destroy (hard-terminate) the bad process.
+	 This happens when:
+	 - the stack went above the absolute limit
+	   (VM switches back to scheduler)
+	 - a halted process cannot execute its interrupt
+	   actions (win32 only)
+	"
+	(id := p id) ~~ 0 ifTrue:[
+	    id notNil ifTrue:[
+		'Processor [warning]: problem with process ' errorPrint.
+		id errorPrint.
+		(nm := p name) notNil ifTrue:[
+		    ' (' errorPrint. nm errorPrint. ')' errorPrint.
+		].
+
+		ok == #halted ifTrue:[
+		    "/ that process was halted (win32 only)
+		    p state:#halted.
+		   '; stopped it.' errorPrintCR.
+		   self suspend:p.
+		] ifFalse:[
+		   '; hard-terminate it.' errorPrintCR.
+		   'Processor [info]: cleanup may take a while if stack is huge' infoPrintCR.
+		   p state:#cleanup.
+		   self terminateNoSignal:p.
+		]
+	    ]
+	]
     ].
     zombie notNil ifTrue:[
-        self class threadDestroy:zombie.
-        zombie := nil
+	self class threadDestroy:zombie.
+	zombie := nil
     ].
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
 
@@ -1673,48 +1674,48 @@
     "
     newPrio := prio.
     newPrio < 1 ifTrue:[
-        newPrio := 1.
+	newPrio := 1.
     ] ifFalse:[
-        newPrio > HighestPriority ifTrue:[
-            newPrio := HighestPriority
-        ]
+	newPrio > HighestPriority ifTrue:[
+	    newPrio := HighestPriority
+	]
     ].
 
     [
-        wasBlocked := OperatingSystem blockInterrupts.
-
-        aProcess setPriority:newPrio.
-
-        oldList := quiescentProcessLists at:oldPrio.
-        oldList notNil ifTrue:[
-            (oldList removeIdentical:aProcess ifAbsent:nil) notNil ifTrue:[
-                newList := quiescentProcessLists at:newPrio.
-                newList isNil ifTrue:[
-                    quiescentProcessLists at:newPrio put:(newList := LinkedList new).
-                ].
-                newList addLast:aProcess.
-
-                "if its the current process lowering its prio
-                 or another one raising, we have to reschedule"
-
-                aProcess == activeProcess ifTrue:[
-                    currentPriority := newPrio.
-                    newPrio < oldPrio ifTrue:[
-                        self threadSwitch:scheduler.
-                    ]
-                ] ifFalse:[
-                    newPrio > currentPriority ifTrue:[
-                        self threadSwitch:aProcess.
-                    ]
-                ].
-                timeSliceNeededSemaphore notNil ifTrue:[
-                    "/ tell timeslicer, that some work might be needed...
-                    timeSliceNeededSemaphore signalIf.
-                ]       
-            ]
-        ]
+	wasBlocked := OperatingSystem blockInterrupts.
+
+	aProcess setPriority:newPrio.
+
+	oldList := quiescentProcessLists at:oldPrio.
+	oldList notNil ifTrue:[
+	    (oldList removeIdentical:aProcess ifAbsent:nil) notNil ifTrue:[
+		newList := quiescentProcessLists at:newPrio.
+		newList isNil ifTrue:[
+		    quiescentProcessLists at:newPrio put:(newList := LinkedList new).
+		].
+		newList addLast:aProcess.
+
+		"if its the current process lowering its prio
+		 or another one raising, we have to reschedule"
+
+		aProcess == activeProcess ifTrue:[
+		    currentPriority := newPrio.
+		    newPrio < oldPrio ifTrue:[
+			self threadSwitch:scheduler.
+		    ]
+		] ifFalse:[
+		    newPrio > currentPriority ifTrue:[
+			self threadSwitch:aProcess.
+		    ]
+		].
+		timeSliceNeededSemaphore notNil ifTrue:[
+		    "/ tell timeslicer, that some work might be needed...
+		    timeSliceNeededSemaphore signalIf.
+		]
+	    ]
+	]
     ] ensure:[
-        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
     ]
 
     "Modified: / 4.8.1998 / 00:08:54 / cg"
@@ -1764,21 +1765,21 @@
 
     s := aProcess state.
     s == #osWait ifTrue:[
-        'Processor [warning]: bad resume: #osWait' errorPrintCR.
-        "/ MiniDebugger enterWithMessage:'bad resume: state osWait'.
-        ^ false.
+	'Processor [warning]: bad resume: #osWait' errorPrintCR.
+	"/ MiniDebugger enterWithMessage:'bad resume: state osWait'.
+	^ false.
     ].
     s == #stopped ifTrue:[
-        "by definition, stopped processes cannot be resumed"
-        ^ false.
+	"by definition, stopped processes cannot be resumed"
+	^ false.
     ].
 
     aProcess == activeProcess ifTrue:[
-        "special handling for waiting schedulers"
-        aProcess == scheduler ifTrue:[
-            suspendScheduler := false.
-        ].
-        ^ false
+	"special handling for waiting schedulers"
+	aProcess == scheduler ifTrue:[
+	    suspendScheduler := false.
+	].
+	^ false
     ].
 
     wasBlocked := OperatingSystem blockInterrupts.
@@ -1788,26 +1789,26 @@
     l := quiescentProcessLists at:pri.
     "if already running, ignore"
     l notNil ifTrue:[
-        (l identityIndexOf:aProcess) ~~ 0 ifTrue:[
-            wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
-            ^ false
-        ]
+	(l identityIndexOf:aProcess) ~~ 0 ifTrue:[
+	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+	    ^ false
+	]
     ] ifFalse:[
-        l := LinkedList new.
-        quiescentProcessLists at:pri put:l.
+	l := LinkedList new.
+	quiescentProcessLists at:pri put:l.
     ].
     l addLast:aProcess.
     aProcess state:#run.
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
 
     pri > currentPriority ifTrue:[
-        "must reschedule"
-        ^ true.
+	"must reschedule"
+	^ true.
     ].
 
     timeSliceNeededSemaphore notNil ifTrue:[
-        "/ tell timeslicer, that some work might be needed...
-        timeSliceNeededSemaphore signalIf.
+	"/ tell timeslicer, that some work might be needed...
+	timeSliceNeededSemaphore signalIf.
     ].
     ^ false.
 
@@ -1839,8 +1840,8 @@
      if its prio is higher than the currently running prio, switch to it."
 
     (self makeRunnable:aProcess) ifTrue:[
-        "aProcess prio is higher; immediately transfer control to it"
-        self threadSwitch:aProcess.
+	"aProcess prio is higher; immediately transfer control to it"
+	self threadSwitch:aProcess.
     ].
 !
 
@@ -1860,8 +1861,8 @@
      If the process is the current one, reschedule.
 
      Notice:
-         This method should only be called by Process>>suspend or
-         Process>>suspendWithState:"
+	 This method should only be called by Process>>suspend or
+	 Process>>suspendWithState:"
 
     |pri l p wasBlocked|
 
@@ -1869,30 +1870,30 @@
      some debugging stuff
     "
     aProcess isNil ifTrue:[
-        InvalidProcessSignal raiseRequestWith:aProcess errorString:'nil suspend'.
-        ^ self
+	InvalidProcessSignal raiseRequestWith:aProcess errorString:'nil suspend'.
+	^ self
     ].
     aProcess id isNil ifTrue:[
-        InvalidProcessSignal raiseRequestWith:aProcess errorString:'bad suspend: already dead'.
-        self threadSwitch:scheduler.
-        ^ self
+	InvalidProcessSignal raiseRequestWith:aProcess errorString:'bad suspend: already dead'.
+	self threadSwitch:scheduler.
+	^ self
     ].
     aProcess == scheduler ifTrue:[
-        "only the scheduler may suspend itself"
-        activeProcess == scheduler ifTrue:[
-            suspendScheduler := true.
-            [suspendScheduler] whileTrue:[
-                self dispatch.
-            ].
-            ^ self
-        ].
-
-        InvalidProcessSignal raiseRequestWith:aProcess errorString:'attempt to suspend scheduler'.
-        ^ self
+	"only the scheduler may suspend itself"
+	activeProcess == scheduler ifTrue:[
+	    suspendScheduler := true.
+	    [suspendScheduler] whileTrue:[
+		self dispatch.
+	    ].
+	    ^ self
+	].
+
+	InvalidProcessSignal raiseRequestWith:aProcess errorString:'attempt to suspend scheduler'.
+	^ self
     ].
 
     aProcess hasInterruptActions ifTrue:[
-        aProcess interrupt.
+	aProcess interrupt.
     ].
 
     wasBlocked := OperatingSystem blockInterrupts.
@@ -1904,23 +1905,23 @@
      the ifAbsent block, because [] is a shared cheap block, created at compile time
     "
     (l isNil or:[(l removeIdentical:aProcess ifAbsent:nil) isNil]) ifTrue:[
-        "/ 'Processor [warning]: bad suspend: process is not running' errorPrintCR.
-        "/ MiniDebugger enterWithMessage:'bad suspend: process is not running'.
-        aProcess == activeProcess ifTrue:[
-            self threadSwitch:scheduler.
-        ].
-        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
-        ^ self
+	"/ 'Processor [warning]: bad suspend: process is not running' errorPrintCR.
+	"/ MiniDebugger enterWithMessage:'bad suspend: process is not running'.
+	aProcess == activeProcess ifTrue:[
+	    self threadSwitch:scheduler.
+	].
+	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+	^ self
     ].
 
     (aProcess == activeProcess) ifTrue:[
-        "we can immediately switch sometimes"
-        l isEmpty ifTrue:[
-            p := scheduler
-        ] ifFalse:[
-            p := l first
-        ].
-        self threadSwitch:p
+	"we can immediately switch sometimes"
+	l isEmpty ifTrue:[
+	    p := scheduler
+	] ifFalse:[
+	    p := l first
+	].
+	self threadSwitch:p
     ].
 
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
@@ -1967,16 +1968,16 @@
 
     aProcess isNil ifTrue:[^ self].
     aProcess == scheduler ifTrue:[
-        InvalidProcessSignal raiseWith:aProcess errorString:'attempt to terminate scheduler'.
-        ^ self
+	InvalidProcessSignal raiseWith:aProcess errorString:'attempt to terminate scheduler'.
+	^ self
     ].
 
     wasBlocked := OperatingSystem blockInterrupts.
 
     id := aProcess id.
     id isNil ifTrue:[   "already dead"
-        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
-        ^ self
+	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+	^ self
     ].
 
     aProcess setId:nil state:#dead.
@@ -1986,31 +1987,31 @@
     pri := aProcess priority.
     l := quiescentProcessLists at:pri.
     l notNil ifTrue:[
-        (l removeIdentical:aProcess ifAbsent:nil) "notNil ifTrue:[
-            l isEmpty ifTrue:[
-                quiescentProcessLists at:pri put:nil
-            ]
-        ]."
+	(l removeIdentical:aProcess ifAbsent:nil) "notNil ifTrue:[
+	    l isEmpty ifTrue:[
+		quiescentProcessLists at:pri put:nil
+	    ]
+	]."
     ].
 
     aProcess == activeProcess ifTrue:[
-        "
-         hard case - it's the currently running process
-         we must have the next active process destroy this one
-         (we cannot destroy the chair we are sitting on ... :-)
-        "
-        zombie notNil ifTrue:[
-            self error:'active process is zombie' mayProceed:true.
-            self class threadDestroy:zombie.
-        ].
-
-        self unRemember:aProcess.
-        zombie := id.
-
-        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
-        self threadSwitch:scheduler.
-        "not reached"
-        ^ self
+	"
+	 hard case - it's the currently running process
+	 we must have the next active process destroy this one
+	 (we cannot destroy the chair we are sitting on ... :-)
+	"
+	zombie notNil ifTrue:[
+	    self error:'active process is zombie' mayProceed:true.
+	    self class threadDestroy:zombie.
+	].
+
+	self unRemember:aProcess.
+	zombie := id.
+
+	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+	self threadSwitch:scheduler.
+	"not reached"
+	^ self
     ].
 
     self unRemember:aProcess.
@@ -2033,16 +2034,16 @@
     wasBlocked := OperatingSystem blockInterrupts.
 
     activeProcess == scheduler ifTrue:[
-        'Processor [warning]: scheduler tries to yield' errorPrintCR.
-        ^ self
+	'Processor [warning]: scheduler tries to yield' errorPrintCR.
+	^ self
     ].
 
     "
      debugging consistency check - will be removed later
     "
     activeProcess priority ~~ currentPriority ifTrue:[
-        'Processor [warning]: process changed its priority' errorPrintCR.
-        currentPriority := activeProcess priority.
+	'Processor [warning]: process changed its priority' errorPrintCR.
+	currentPriority := activeProcess priority.
     ].
 
     l := quiescentProcessLists at:currentPriority.
@@ -2052,25 +2053,25 @@
      debugging consistency checks - will be removed later
     "
     sz == 0 ifTrue:[
-        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
-        'Processor [warning]: empty runnable list' errorPrintCR.
-        ^ self
+	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+	'Processor [warning]: empty runnable list' errorPrintCR.
+	^ self
     ].
 
     "
      check if the running process is not the only one
     "
     sz ~~ 1 ifTrue:[
-        "
-         bring running process to the end
-        "
-        l removeFirst.
-        l addLast:activeProcess.
-
-        "
-         and switch to first in the list
-        "
-        self threadSwitch:(l first).
+	"
+	 bring running process to the end
+	"
+	l removeFirst.
+	l addLast:activeProcess.
+
+	"
+	 and switch to first in the list
+	"
+	self threadSwitch:(l first).
     ].
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
 
@@ -2170,14 +2171,14 @@
     i := TimeSlicingPriorityLimit.
     [(i > 0) and:[(list := quiescentProcessLists at:i) size <= 1]] whileTrue: [i := i - 1].
     i ~~ 0 ifTrue: [
-        "/ shuffle that list
-        list addLast:(list removeFirst).
-        anyShuffle := true.
+	"/ shuffle that list
+	list addLast:(list removeFirst).
+	anyShuffle := true.
     ].
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
     anyShuffle ifFalse:[
-        "/ wait for the scheduler to make some process runnable...
-        timeSliceNeededSemaphore wait.
+	"/ wait for the scheduler to make some process runnable...
+	timeSliceNeededSemaphore wait.
     ].
 
     "Modified: / 4.8.1998 / 00:13:32 / cg"
@@ -2191,37 +2192,37 @@
     timeSliceNeededSemaphore := Semaphore new name:'timeSlice needed'.
 
     timeSliceProcess := [
-        [
-            |myDelay t flipFlop|
-
-            myDelay := Delay forMilliseconds:(t := TimeSliceInterval).
-            flipFlop := true.
-
-            'Processor [info]: timeslicer started' infoPrintCR.
-            [true] whileTrue: [
-                t ~~ TimeSliceInterval ifTrue:[
-                    "/ interval changed -> need a new delay
-                    myDelay delay:(t := TimeSliceInterval).
-                ].
-                myDelay wait.
-                self slice.
-
-                "/ every other tick, recompute priorities.
-                flipFlop := flipFlop not.
-                flipFlop ifTrue:[
-                    scheduledProcesses notNil ifTrue:[
-                        supportDynamicPriorities == true ifTrue:[
-                            self recomputeDynamicPriorities.
-                        ].
-                        scheduledProcesses removeAll.
-                    ].
-                    scheduledProcesses := IdentitySet new.
-                ].
-            ]
-        ] ifCurtailed:[
-            timeSliceProcess := nil.
-            'Processor [info]: timeslicer finished' infoPrintCR.
-        ]
+	[
+	    |myDelay t flipFlop|
+
+	    myDelay := Delay forMilliseconds:(t := TimeSliceInterval).
+	    flipFlop := true.
+
+	    'Processor [info]: timeslicer started' infoPrintCR.
+	    [true] whileTrue: [
+		t ~~ TimeSliceInterval ifTrue:[
+		    "/ interval changed -> need a new delay
+		    myDelay delay:(t := TimeSliceInterval).
+		].
+		myDelay wait.
+		self slice.
+
+		"/ every other tick, recompute priorities.
+		flipFlop := flipFlop not.
+		flipFlop ifTrue:[
+		    scheduledProcesses notNil ifTrue:[
+			supportDynamicPriorities == true ifTrue:[
+			    self recomputeDynamicPriorities.
+			].
+			scheduledProcesses removeAll.
+		    ].
+		    scheduledProcesses := IdentitySet new.
+		].
+	    ]
+	] ifCurtailed:[
+	    timeSliceProcess := nil.
+	    'Processor [info]: timeslicer finished' infoPrintCR.
+	]
     ] newProcess.
     timeSliceProcess priority:HighestPriority.
     timeSliceProcess name:'time slicer'.
@@ -2242,10 +2243,10 @@
     "stop preemptive scheduling (timeSlicing)"
 
     timeSliceProcess notNil ifTrue: [
-        timeSliceProcess terminate.
-        timeSliceProcess := nil.
-        scheduledProcesses := nil.
-        timeSliceNeededSemaphore := nil.
+	timeSliceProcess terminate.
+	timeSliceProcess := nil.
+	scheduledProcesses := nil.
+	timeSliceNeededSemaphore := nil.
     ]
 
     "
@@ -2871,28 +2872,28 @@
 
 timeoutHandlerProcess
     (timeoutHandlerProcess isNil or:[timeoutHandlerProcess isDead]) ifTrue:[
-        timeoutHandlerProcess :=
-                [
-                    [
-                        [true] whileTrue:[
-                            [
-                                self timeoutHandlerProcessLoop
-                            ] on:Exception do:[:ex|
-                                "ignore errors, but tell the user"
-                                ('ProcessorScheduler [warning]: error while handling timeouts in TimeoutHandlerProcess: ''' , ex description , '''') infoPrintCR.
+	timeoutHandlerProcess :=
+		[
+		    [
+			[true] whileTrue:[
+			    [
+				self timeoutHandlerProcessLoop
+			    ] on:Exception do:[:ex|
+				"ignore errors, but tell the user"
+				('ProcessorScheduler [warning]: error while handling timeouts in TimeoutHandlerProcess: ''' , ex description , '''') infoPrintCR.
 "/                                thisContext fullPrintAll.
-                            ].
-                        ] 
-                    ] ensure:[
-                        timeoutHandlerProcess := nil
-                    ].
-                ] newProcess.
-
-        timeoutHandlerProcess 
-            priority:TimingPriority;
-            name:'Timeout handler';
-            beSystemProcess;
-            resume.
+			    ].
+			]
+		    ] ensure:[
+			timeoutHandlerProcess := nil
+		    ].
+		] newProcess.
+
+	timeoutHandlerProcess
+	    priority:TimingPriority;
+	    name:'Timeout handler';
+	    beSystemProcess;
+	    resume.
     ].
     ^ timeoutHandlerProcess.
 
@@ -2945,7 +2946,7 @@
      or a timeout to occur."
 
     |nReady index sema action wasBlocked err fd readyIndex
-     readableResultFdArray writableResultFdArray newProcessMaybeReady|
+     newProcessMaybeReady|
 
     "/ must enable interrupts, to be able to get out of a
     "/ long wait (especially, to handle sigChild in the meantime)
@@ -3025,8 +3026,12 @@
     ].
 
     newProcessMaybeReady := false.
-    readableResultFdArray := Array new:40.
-    writableResultFdArray := Array new:40.
+    readableResultFdArray size < readFdArray size ifTrue:[
+        readableResultFdArray := Array new:(40 max:readFdArray size).
+    ].
+    writableResultFdArray size < writeFdArray size ifTrue:[
+        writableResultFdArray := Array new:(40 max:writeFdArray size).
+    ].
 
     nReady := OperatingSystem
                 selectOnAnyReadable:readFdArray
@@ -3146,49 +3151,49 @@
       readFdArray/writeFdArray in the debugger)"
 
     readFdArray keysAndValuesDo:[:idx :fd |
-        |rslt sema|
-
-        (fd notNil "and:[fd >= 0]") ifTrue:[
-            rslt := OperatingSystem
-                        selectOnAnyReadable:(Array with:fd)
-                                   writable:nil
-                                  exception:nil
-                                withTimeOut:0.
-
-            (rslt == #error or:[rslt isNil and:[OperatingSystem lastErrorSymbol == #EBADF]]) ifTrue:[
-                "/ ('Processor [info]: removing invalid read-select fileDescriptor: ' , fd printString) infoPrintCR.
-                readFdArray at:idx put:nil.
-                readCheckArray at:idx put:nil.
-                OperatingSystem clearLastErrorNumber.
-                (sema := readSemaphoreArray at:idx) notNil ifTrue:[
-                    readSemaphoreArray at:idx put:nil.
-                    sema signal.
-                ].
-            ]
-        ].
+	|rslt sema|
+
+	(fd notNil "and:[fd >= 0]") ifTrue:[
+	    rslt := OperatingSystem
+			selectOnAnyReadable:(Array with:fd)
+				   writable:nil
+				  exception:nil
+				withTimeOut:0.
+
+	    (rslt == #error or:[rslt isNil and:[OperatingSystem lastErrorSymbol == #EBADF]]) ifTrue:[
+		"/ ('Processor [info]: removing invalid read-select fileDescriptor: ' , fd printString) infoPrintCR.
+		readFdArray at:idx put:nil.
+		readCheckArray at:idx put:nil.
+		OperatingSystem clearLastErrorNumber.
+		(sema := readSemaphoreArray at:idx) notNil ifTrue:[
+		    readSemaphoreArray at:idx put:nil.
+		    sema signal.
+		].
+	    ]
+	].
     ].
 
     writeFdArray keysAndValuesDo:[:idx :fd |
-        |rslt sema|
-
-        fd notNil ifTrue:[
-            rslt := OperatingSystem
-                        selectOnAnyReadable:nil
-                                   writable:(Array with:fd)
-                                  exception:nil
-                                withTimeOut:0.
-
-            (rslt == #error or:[rslt isNil and:[OperatingSystem lastErrorSymbol == #EBADF]]) ifTrue:[
-                "/ ('Processor [info]: removing invalid write-select fileDescriptor: ' , fd printString) infoPrintCR.
-                writeFdArray at:idx put:nil.
-                writeCheckArray at:idx put:nil.
-                OperatingSystem clearLastErrorNumber.
-                (sema := writeSemaphoreArray at:idx) notNil ifTrue:[
-                    writeSemaphoreArray at:idx put:nil.
-                    sema signal.
-                ].
-            ]
-        ]
+	|rslt sema|
+
+	fd notNil ifTrue:[
+	    rslt := OperatingSystem
+			selectOnAnyReadable:nil
+				   writable:(Array with:fd)
+				  exception:nil
+				withTimeOut:0.
+
+	    (rslt == #error or:[rslt isNil and:[OperatingSystem lastErrorSymbol == #EBADF]]) ifTrue:[
+		"/ ('Processor [info]: removing invalid write-select fileDescriptor: ' , fd printString) infoPrintCR.
+		writeFdArray at:idx put:nil.
+		writeCheckArray at:idx put:nil.
+		OperatingSystem clearLastErrorNumber.
+		(sema := writeSemaphoreArray at:idx) notNil ifTrue:[
+		    writeSemaphoreArray at:idx put:nil.
+		    sema signal.
+		].
+	    ]
+	]
     ].
 
     "Modified: 12.4.1996 / 09:32:58 / stefan"
@@ -3356,11 +3361,11 @@
 !ProcessorScheduler class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.265 2013-02-08 21:33:05 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.266 2013-03-25 12:15:24 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.265 2013-02-08 21:33:05 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.266 2013-03-25 12:15:24 cg Exp $'
 ! !