Delay and threads question

Bob Arning arning at charm.net
Thu Dec 5 01:30:38 UTC 2002


On Wed, 04 Dec 2002 17:09:41 -0800 Derek Brans <brans at nerdonawire.com> 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?

Whose #initialize?

>If so, why doesn't the process that called "new" get trapped?

Trapped. Is that the same as blocked? If yes, then it does.

>If not, how should startTimer be called?

If this is to be asynchronous, then

 	[[delay wait. true] whileTrue: [self save]] fork.

will get it running in a separate process. Or, in slightly simpler terms,

 	[[delay wait. self save] repeat] fork.

The next problem to solve is to be sure these two processes (the original and the one forked) don't step on each other's toes while dealing with what needs to be saved. Semaphores can help here.

Cheers,
Bob



More information about the Squeak-dev mailing list