Delay and threads question
Stephan Rudlof
sr at evolgo.de
Thu Dec 5 01:34:31 UTC 2002
Derek Brans wrote:
> I want an object to do something every 10 minutes.
>
> I have the following code:
>
> startTimer
> | delay |
> delay _ Delay forMilliseconds: 10 * 60 * 1000.
> [delay wait. true] whileTrue: [self save]
>
> My question: is it save safe to call self startTimer from initialize?
In the light of the next question: No.
> If so, why doesn't the process that called "new" get trapped?
It gets trapped, means it waits in the semaphore of the Delay.
> If not, how should startTimer be called?
Possibly
startTimer
| delay |
delay _ Delay forMilliseconds: 10 * 60 * 1000.
[[delay wait. true] whileTrue: [self save]] fork
or
[[delay wait. true] whileTrue: [self save]]
forkAt: someHigherPriority
for the last line may work (not tested).
Processes with same prio don't interrupt each other,
they just get a chance if the previous scheduled one with same prio
- will be interrupted by another one with higher prio, or
- has to be wait itself.
Greetings,
Stephan
>
> Many thanks,
> Derek
>
> Nerd on a Wire: Web and Information Solutions
> Website Design - Database Systems - Site Hosting
> 604.874.6463
> mailto:info at nerdonawire.com
> For more information, visit http://nerdonawire.com
>
>
>
--
Stephan Rudlof (sr at evolgo.de)
"Genius doesn't work on an assembly line basis.
You can't simply say, 'Today I will be brilliant.'"
-- Kirk, "The Ultimate Computer", stardate 4731.3
More information about the Squeak-dev
mailing list
|