|
Process Scheduling (was Re: BlockClosure>>fork problem): msg#00095lang.smalltalk.squeak.beginners
On Feb 20, 2007, at 11:05 , Michael Davies wrote: George, Besides, it interferes with processes because it has a Mutex nowadays. Which is good, but it distorts what you would observe without the Transcript involved. Writing the results into an OrderedCollection will be much faster, and This is because waiting on Delay (or, rather on the Semaphore inside) causes the current process to block, and the next process on the same priority to run. The same could be achieved by "Processor yield" instead of waiting on the Delay. This is "cooperative". Or, you could have a higher-priority scheduler that time-slices the lower-priority ones by suspending them in turn, which does not need cooperation. Without the delay: These processes are too short-lived to ever get interrupted by a higher priority process. So the first one runs to completion, then the second one. Try this instead: a := String new writeStream. p1 := [[a nextPut: $1] repeat] forkAt: Processor userBackgroundPriority. p2 := [[a nextPut: $2] repeat] forkAt: Processor userBackgroundPriority. 10 timesRepeat: [(Delay forMilliseconds: 1) wait]. p1 terminate. p2 terminate. a contents This puts the two processes into a lower priority than the UI process. We then stop the UI process 10 times for one millisecond - this is our scheduler. Each time, the next lower-priority process is given time to run - that is the default scheduling behavior. The result are nicely alternating runs of ones and twos as you would expect: '111111111122222222222111111111111122222222222...' - Bert -
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: BlockClosure>>fork problem, Michael Davies |
|---|---|
| Next by Date: | Creating custom events in a domain., Mispunt |
| Previous by Thread: | Re: BlockClosure>>fork problem, Michael Davies |
| Next by Thread: | Re: BlockClosure>>fork problem, George Herolyants |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |