Pharo /
ProcessPriorityLook at the code in MyTherm>>startLoop. startLoop "set running to true, and use lower priority than the interface" running := true. [self myLoop] forkAt: 49. forkAt: sets the priority lower than the desktop (which is at 50). If it is not lower, when the the endless loop in myLoop( the [block] controlled by repeat), you can't change 'running' to false. With the lower priority, other code can change running to false. myLoop "private. " "running is an instance variable, initialized to false to avoid endless loop." "use startLoop to change running to true and to give this method lower priority" "rand generates between 0 and 1. adjust fudge through MyControl." "heater and cooler are controlled through announcements" | oldCurrentTemp newCurrentTemp rand| oldCurrentTemp := currentTemp. rand := Random new. [ (rand next + fudge + heater - cooler ) >= 0.5 ifTrue: [newCurrentTemp := oldCurrentTemp + bumpTemp] ifFalse: [newCurrentTemp := oldCurrentTemp - bumpTemp]. self currentTemp: newCurrentTemp. "currentTemp: also sends announcements" oldCurrentTemp := newCurrentTemp. (Delay forSeconds: delaySeconds) wait. running ifFalse: [^ nil]. "exits the loop" ] repeat. |